Django 的 Nginx 504 网关超时错误

新手上路,请多包涵

我正在使用 1ClickInstallation 图像在 DigitalOcean 上运行 Django 站点。一切正常,但我遇到了 504 网关超时错误的问题。我在博客上尝试了多种设置,但没有用。以下是我的设置:

 upstream app_server {
    server 127.0.0.1:9000 fail_timeout=0;

}

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

    root /home/django/django_project;
    index index.html index.htm;

    client_max_body_size 4G;
    server_name www.mydomain.com;

    keepalive_timeout 5;

    location ~*  \.(jpg|jpeg|png|gif|ico|css|js|woff2|woff|ttf)$ {
        expires 365d;
    }

    # Your Django project's media files - amend as required
    location /media  {
        alias /home/django/django_project/media/;
    }

    # your Django project's static files - amend as required
    location static/static-only {
        alias /home/django/django_project/static-only/;
    }
    # Django static images
    location /static/django_project/images {
        alias /home/django/django_project/static-only/django_project/images/;
    }

    # Proxy the static assests for the Django Admin panel
    location /static/admin {
       alias /usr/lib/python2.7/dist-packages/django/contrib/admin/static/admin;
    }

    location / {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_redirect off;
        proxy_pass http://app_server;

    }
}

我在以下链接中关注了文档 http://nginx.org/en/docs/http/ngx_http_limit_req_module.html

以下是“wget 127.0.0.1:9000”的结果

在此处输入图像描述

但不知道在哪里添加指令。好心提醒。

原文由 Shazia Nusrat 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 724
2 个回答

我在尝试更改 /etc/nginx/sites-available/django-project 时找到了解决方案。但我需要在 /etc/nginx/nginx.conf Nginx 的全局设置中添加以下行。我添加的行是:

 http {
    ...
    proxy_connect_timeout   10;
    proxy_send_timeout      15;
    proxy_read_timeout      20;
}

我有一个小型网站托管,上面的设置就足够了。但其他人可能会根据自己的需要进行设置。

原文由 Shazia Nusrat 发布,翻译遵循 CC BY-SA 4.0 许可协议

如果您将 uwsgi 与 django 一起使用,那么您可以将 uwsgi_read_timeout 指令添加到 nginx 的配置文件中的位置

location / {
    uwsgi_read_timeout 120;
}

原文由 Lukasz Dynowski 发布,翻译遵循 CC BY-SA 3.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题