我跟着this post为我的django项目服务。该项目与manage.py runserver
运行良好,我想设置它的生产。这里是我的设置文件:用nginx和uWSGI服务django
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
这里的Nginx的错误日志,当我运行/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) ***
不能运行uWSGI为根?
谢谢你的答案。我改为666,但它仍然是一样的。我编辑了我的问题并添加了错误日志。是否因为我以root身份运行? – Terry
nginx中unix套接字路径的语法是错误的,你需要用unix前缀: – roberto