我有一个django应用程序。我似乎无法让nginx正确地提供静态文件,但这不是这个问题。
当前的问题是,在遵循本指南时:https://gist.github.com/evildmp/3094281
我尝试使用unix套接字而不是web套接字。
e.g。
server unix:///tmp/uwsgi.sock; # for a file socket
#server 127.0.0.1:8001; # for a web port socket
使用/tmp/uwsgi.sock套接字而不是127.0.0.1:8001网络端口套接字。
问题在于,当我使用网络端口套接字时,我导航到domainname.com:8001,我到达uWSGI服务的网站,但没有加载静态文件。这意味着至少uwsgi正在发挥作用。但是当我切换到文件套接字时,我根本无法让它工作。
我做错了什么?
这是我的nginx.conf:
# nginx.conf
upstream django {
# connect to this socket
# server unix:///tmp/uwsgi.sock; # for a file socket (TRYING TO USE)
server 127.0.0.1:8001; # for a web port socket (RATHER THAN THIS)
}
server {
# the port your site will be served on
listen 8000;
# the domain name it will serve for
server_name .cshenkan.com; # substitute your machine's IP address or FQDN
charset utf-8;
#Max upload size
client_max_body_size 75M; # adjust to taste
# Django media
location /media {
alias /home/ubuntu/sasite-rewrite/media; # your Django pro$
}
location /static {
alias /home/ubuntu/sasite-rewrite/static; # your Django pro$
}
location /assets {
alias /home/ubuntu/sasite-rewrite/assets
}
# Finally, send all non-media requests to the Django server.
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params; # or the uwsgi_params you installe$
}
}
我的base.py设置文件摘要:
STATIC_ROOT = normpath(join(SITE_ROOT, 'static'))
STATIC_URL = '/static/'
STATICFILES_DIRS = (
normpath(join(SITE_ROOT, 'static')),
normpath(join(SITE_ROOT, 'assets')),
)
我在使用网络套接字时如何运行uwsgi:
uwsgi --http:8001 --chdir / home / ubuntu / sasite-rewrite --wsgi-file /home/ubuntu/sasite-rewrite/sasite/wsgi.py
使用unix套接字时如何运行它:
uwsgi --socket /tmp/uwsgi.sock --chdir / home / ubutnu / sasite-rewrite --wsgi-file /home/ubuntu/sasite-rewrite/sasite/wsgi.py
使用unix套接字时,我似乎无法使其工作。
我也不能让nginx提供正确的静态文件,例如,如果我将文件添加到名为1.png或1.txt的媒体目录中,并尝试使用domainname.com:8000/media/1访问它们。 png我总是得到挂起或服务器错误无响应。
我做错了什么?
如何让unix套接字正常工作?我正在使用的命令是否正确?
我也不明白这一点,当我使用网络套接字时,我可以连接到domainname.com:8001并获取没有静态文件的页面,它看起来像废话但是从uwsgi加载。但是使用unix套接字我不知道如何访问uwsgi服务的页面,看看它是否适用于unix套接字。在我开始使用nginx工作之前,我需要解决这个问题,因为我尝试使用带有nginx的web套接字并且仍然没有运气,我希望一旦我的unix套接字设置正确,nginx将更好用。
您可以提供的任何建议或示例?非常感谢,我是一个很长时间的django程序员,但我很少自己部署这些网站。所以我真的在这里苦苦挣扎。
非常感谢任何帮助,谢谢。
答案 0 :(得分:1)
今天我对于使用uwsgi协议的NGINX + Socket Unix也有同样的问题。 我发现NGINX的1.8版本被窃听了。
尝试安装可通过UNIX SOCKET运行的1.10版本。
如果你使用open-SuSE,你可以在这里获得rpm:
或者,直接在官方nginx下载区域: