【问题标题】:django+gunicorn+nginx, django admin return 504 Gateway Time-outdjango+gunicorn+nginx, django admin 返回 504 网关超时
【发布时间】:2018-09-20 20:29:08
【问题描述】:

我正在开发 django+gunicorn+nginx。 在 django 管理员中,我试图删除一个项目“用户”,它链接到数据库中的大量数据,并在 60 秒后返回“504 网关超时”。 然后我尝试更改 nginx 的配置和 gunicorn 的配置,如下所示

在独角兽中:

timeout = 10000

在 nginx 中

    proxy_connect_timeout 50000;
    proxy_read_timeout 50000;
    proxy_send_timeout 50000;

但是无论我做了什么改变,服务器总是在 60 秒后超时!

我能做什么?我一无所知...

而且服务器也关闭了,我什至无法 ssh 进入它。 看起来不是 nginx/gunicorn 配置问题?

ngix.conf

##
# Logging Settings
##

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

##
# Gzip Settings
##

gzip on;
gzip_disable "msie6";

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;

sites-enabled/app.conf

    location / {
    try_files $uri @app;
}

location @app {
    proxy_connect_timeout 50000;
    proxy_read_timeout 50000;
    proxy_send_timeout 50000;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Host $http_host;
    proxy_redirect off;

    proxy_pass http://xxx;
}

【问题讨论】:

  • 制作chanes后是否重启了nginx和gunicorn?
  • 是的,我还有 60 多岁的超时时间..
  • 你确定你正在使用你的配置文件吗?也许尝试使用 gunicorn 手动执行您的 django 应用程序,设置 --timeout 标志并检查它是否有帮助。
  • 是的,我确定它正在使用配置文件,我将文件更新为不同的TIMEOUT值,然后我检查了ps -aux,gunicorn有--timeout xxx运行参数.
  • django admin 本身是否有超时机制?当查询耗时过长会返回超时...?

标签: django nginx gunicorn


【解决方案1】:

在 /etc/nginx/nginx.conf 文件中的 http{ ... } 块中设置超时 ngnix 设置:

http {
    #All block content...

    #Now the timeout settings:

    proxy_connect_timeout 50000;
    proxy_read_timeout 50000;
    proxy_send_timeout 50000;
}

重启nginx

【讨论】:

    猜你喜欢
    • 2013-12-15
    • 2018-05-17
    • 2011-10-04
    • 2016-06-19
    • 2017-03-28
    • 2015-12-25
    • 2013-10-17
    • 2015-12-24
    • 2017-02-05
    相关资源
    最近更新 更多