我跟着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