我的nginx和uwsgi配置完全适用于前一个或两个请求。然后nginx显示502 Bad Gateway。当我重新启动uwsgi服务时,同样的事情再次发生。我正在使用Ubuntu 16.04。这是我的所有conf和错误日志:
nginx conf
:
upstream book {
server unix:///tmp/book.sock;
}
server {
listen 80;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
server_name example.com;
......
add_header X-Frame-Options DENY;
add_header X-Content-Type-Options nosniff;
charset utf-8;
client_max_body_size 100M;
access_log /var/log/nginx/example.com_access.log;
error_log /var/log/nginx/example.com_error.log;
location /media {
alias /home/prism/prod/example.com/media;
}
location /static {
alias /home/prism/prod/example.com/static;
}
location / {
uwsgi_pass book;
include /etc/nginx/uwsgi_params;
}
}
/var/log/nginx/example.com_error.log
2016/05/25 17:44:26 [error] 5230#5230: *214 connect() to unix:///tmp/book.sock failed (111: Connection refused) while connecting to upstream, client: 27.*.*.*, server: example.com, request: "GET / HTTP/2.0", upstream: "uwsgi://unix:///tmp/book.sock:", host: "example.com"
hiren.ini
[uwsgi]
chdir=/home/prism/prod/example.com
home = /home/prism/prod/example.com/.env
module=hiren.wsgi
master=True
process = 5
pidfile=/tmp/book.pid
socket= /tmp/book.sock
vacuum=True
max-requests=5000
daemonize=/home/prism/prod/example.com/hiren.log
uid = www-data
gid = www-data
die-on-term = true
和服务文件:
[Unit]
Description=uWSGI instance to serve example.com
[Service]
User=prism
ExecStart=/bin/bash -c 'cd /home/prism/prod/example.com; source .env/bin/activate; uwsgi --ini hiren.ini'
[Install]
WantedBy=multi-user.target
答案 0 :(得分:1)
通过调整systemd脚本来解决问题
[Unit]
Description=uWSGI instance to serve example.com
[Service]
ExecStart=/bin/bash -c 'su prism; cd /home/prism/prod/example.com; source .env/bin/activate; uwsgi --ini hiren.ini'
[Install]
WantedBy=multi-user.target
答案 1 :(得分:0)
如果您能够在虚拟环境中运行uwsgi和.ini文件,并且nginx正常启动,则问题出在systemd文件上。