Django Admin一直返回504超时(nginx + uWSGI)

时间:2017-12-04 04:33:10

标签: django nginx django-admin uwsgi systemd

这是我的nginx配置:

server {
    listen 80;
    listen [::]:80;

    root /var/www/html;

    index index.html index.htm index.nginx-debian.html;

    server_name www.nameOfSite.id nameOfSite.id;

    access_log  off;
    error_log  /var/www/log_nginx/error.log;   
    gzip on;
    gzip_disable "msie6";

    client_header_timeout 180s;
    client_body_timeout 180s;
    client_max_body_size 100m;

    proxy_connect_timeout   120s;
    proxy_send_timeout      180s;
    proxy_read_timeout      180s;
    send_timeout            600s;

    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    location /static {    
        alias /var/www/django/static;    
    }

    location /media {    
       alias /var/www/django/media;    
    }

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        include         uwsgi_params;
        uwsgi_read_timeout 500;
        uwsgi_send_timeout 500;
        uwsgi_pass      unix:/var/www/uwsgi_texas.sock;
    }

}

这是我在/var/www/texas_uwsgi.ini中的uWSGI ini文件:

[uwsgi]
socket = /var/www/uwsgi_texas.sock
chdir = /var/www/django/
wsgi-file = /var/www/django/django/wsgi.py
processes = 8
threads = 1
master = true
harakiri = 900
chmod-socket = 777
vacuum = true

这是我在/etc/systemd/system/texas.service中的服务文件:

[Unit]
Description=TEXAS
After=syslog.target

[Service]
ExecStart=/usr/local/bin/uwsgi --ini /var/www/texas_uwsgi.ini
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=main

[Install]
WantedBy=multi-user.target

问题是,当我为一个具有大量内联对象和字段的Model对象进入Django管理员时,它会一直返回504超时,因为处理时间超过60秒。我检查了我的NGINX,uWSGI配置,我找不到如何增加这个“60秒超时”的解决方案。其余页面工作正常。

在我的nginx配置中,我已经尝试过:

proxy_connect_timeout   120s;
proxy_send_timeout      180s;
proxy_read_timeout      180s;
send_timeout            600s;
uwsgi_read_timeout 500;
uwsgi_send_timeout 500;

这是我尝试打开“模型管理员”页面时的结果:

the error

1 个答案:

答案 0 :(得分:1)

也许可以使用raw_id字段(对于内联模型)在必要时加载管理员。

参考:{{3}}

这样做可以绕过504错误