2016-05-25 5 views
1

Конфигурация nginx и uwsgi отлично работает для первого или двух запросов. Затем nginx показывает 502 Bad Gateway. Когда я перезапускаю службу uwsgi, то снова происходит то же самое. Я использую Ubuntu 16.04. Вот мой все конф и журнал ошибок:nginx uwsgi 502 Bad Gateway

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

ошибка Bad Gateway указывает на связь между Nginx и ваше приложение разбито, так что я бы не заподозрил Nginx конф здесь. Обычно это происходит потому, что приложение не отвечает. Вы проверили, что служба uWSGI все еще работает? У вас есть журнал uWSGI? –

ответ

0

Решена проблема щипая 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