我正在尝试使用nginx和uwsgi在ubuntu 14.04服务器64位上部署我的django Web应用程序。我遵循了this教程,但我收到了502错误的网关错误。
我遵循的步骤:
uwsgi --http :8001 --home /home/pnb/pnb --chdir /home/pnb/pnb/pnb -w pnb.wsgi
/etc/uwsgi/sites
中创建一个pnb.ini文件:[uwsgi]
project = pnb # Virtual environment name in home directory
base = /home/pnb # Home directory path
chdir = /home/pnb/pnb # Virtual Env Directory
home = /home/pnb/pnb/pnb #Django Project Directory with manage.py
module = pnb.wsgi:application # project name
master = true
processes = 5
socket = /home/pnb/pnb/pnb/pnb.sock
chmod-socket = 664
vacuum = true
/etc/init/uwsgi.conf
描述“Emperor模式下的uWSGI应用服务器”
start on runlevel [2345]
stop on runlevel [!2345]
setuid pnb
setgid www-data
exec /usr/local/bin/uwsgi --emperor /etc/uwsgi/sites
created和nginx配置文件/etc/nginx/sites/available/pnb
:
上游django { server unix:/home/pnb/pnb/pnb/pnb.sock; }
服务器{ 听80; server_name pnb.com; #IP地址或FQDN
location /static/ {
root /home/pnb/pnb/pnb;
}
location / {
include uwsgi_params;
uwsgi_pass unix:/home/pnb/pnb/pnb/pnb.sock;
}
}
使用此配置,当我访问pnb.com时,我收到502 bad gateway
错误。
有nginx错误日志:
2016/06/12 06:30:10 [crit] 12517#0: *4 connect() to unix:/home/pnb/pnb/pnb/pnb.sock failed (2: No such file or directory) while connecting to upstream, client: 106.218.89.140, server: pnb.com, request: "GET / HTTP/1.1", upstream: "uwsgi://unix:/home/pnb/pnb/pnb/pnb.sock:", host: "pnb.com"
如何更正此错误?
编辑:
现在我检查了pnb.sock文件没有在目录中创建。是否必须对文件权限执行某些操作?
相同的配置适用于我的另一个项目。