[英]Nginx 504 Gateway Timeout Error for Django
我正在使用 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”的結果
但在何處添加指令是沒有意義的。 好心提醒。
如果您正在使用uwsgi使用Django,那么你可能在位置處添加uwsgi_read_timeout指令的nginx的配置文件
location / {
uwsgi_read_timeout 120;
}
我在嘗試更改/etc/nginx/sites-available/django-project
找到了解決方案。 但是我需要在/etc/nginx/nginx.conf
添加以下幾行 Nginx 的全局設置。 我添加的行是:
http {
...
proxy_connect_timeout 10;
proxy_send_timeout 15;
proxy_read_timeout 20;
}
我有一個托管的小網站,上面的設置就足夠了。 但其他人可能會根據自己的需要進行設置。
我知道我遲到了,但是在嘗試了許多這些建議(和其他建議)之后,我最終發現我的超時發生在我的DNS 上- 如果您使用的是Amazon 負載均衡器,他們設置了“空閑超時”默認為 120 秒。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.