Nginx抛出504网关超时,而uwsgi以200响应

时间:2016-07-04 19:48:33

标签: django nginx uwsgi

我正在使用uWSGI和nginx运行Django应用程序。使用django开发服务器一切正常。当我把它移到uWSGI时,我观察到一个奇怪的(是吗?!)行为。请求被正确处理,uWSGI以状态代码200响应。浏览器只是等待,然后最终超时。

以下是uWSGI日志:

*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 10342)
spawned uWSGI worker 1 (pid: 10345, cores: 1)
[pid: 10345|app: 0|req: 1/1] xx.xx.xx.xx () {48 vars in 870 bytes} [Mon Jul 4 19:33:07 2016] GET /kyc/dashboard/ => generated 28501 bytes in 7461 msecs (HTTP/1.1 200) 2 headers in 88 bytes (1 switches on core 0)

Nginx error.log

2016/07/04 19:38:14 [error] 10379#0: *1 upstream timed out (110: Connection timed out) while reading upstream, client: xx.xx.xx.xx, server: _, request: "GET /kyc/dashboard/ HTTP/1.1", upstream: "uwsgi://unix:///home/ubuntu/myapp.sock:", host: "xx.xx.xx.xx", referrer: "http://xx.xx.xx.xx/kyc/login/"

uwsgi config

[uwsgi]
chdir=/home/ubuntu/myapp
uid=ubuntu
gid=ubuntu
module=myapp.wsgi:application
master=True
workers=1
pidfile=/tmp/myapp-master.pid
vacuum=True
logger= file:/var/log/uwsgi/myapp.log
logger = socket:xx.xx.xx.xx:5959
socket=/home/ubuntu/myapp.sock
chmod-socket=777
die-on-term=True

nginx conf

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    gzip on;
    gzip_disable "msie6";

    upstream myapp {
        server unix:///home/ubuntu/myapp.sock;
    }

    server {
        listen 80;
        server_name _;

        location /static {
            alias /home/ubuntu/myapp/static_files;
        }

        location /media {
            alias /home/ubuntu/myapp/media_files;
        }

        location / {
        uwsgi_pass  myapp;
    uwsgi_read_timeout 300;
        include     /etc/nginx/uwsgi_params; # the uwsgi_params file you installed
        }
    }

}

0 个答案:

没有答案