我跟着this post来为我的django项目服务。该项目与manage.py runserver
运行良好,我想将其设置为生产。以下是我的设置文件:
nginx.conf
:
upstream django {
server /tmp/vc.sock;
#server 10.9.1.137:8002;
}
server {
listen 8001;
server_name 10.9.1.137;
charset utf-8;
client_max_body_size 25M;
location /media {
alias /home/deploy/vc/media;
}
location /static {
alias /home/deploy/vc/static;
}
location / {
uwsgi_pass django;
include /etc/nginx/uwsgi_params;
}
}
uwsgi.ini
:
[uwsgi]
chdir = /home/deploy/vc
wsgi-file = vc/wsgi.py
master = true
processes = 2
#socket = :8002
socket = /tmp/vc.sock
chmod-socket = 666
vacuum = true
如果我使用TCP端口套接字(server 10.9.1.137:8002
和socket = :8002
),它会好起来的。但是,如果我将它们注释掉并使用Unix套接字(server /tmp/vc.sock
和socket = /tmp/vc.sock
),服务器将返回502错误。我该如何解决?
EDIT
这是我运行/etc/init.d/nginx restart
nginx: [emerg] invalid host in upstream "/tmp/vc.sock" in /etc/nginx/conf.d/vc.conf:2
nginx: configuration file /etc/nginx/nginx.conf test failed
这是我运行uwsgi --ini vc/uwsgi.ini
时的警告:
*** WARNING: you are running uWSGI as root !!! (use the --uid flag) ***
我不能以root身份运行uWSGI吗?
答案 0 :(得分:5)
unix套接字路径的nginx语法错误,需要加前缀 它与unix:
答案 1 :(得分:0)
检查你的nginx错误日志,很可能是告诉你它没有socket的权限。 Unix套接字支持文件系统权限,因此nginx必须对套接字文件具有写权限。简答:664还不够,你需要666