我正在使用 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 许可协议
我在尝试更改
/etc/nginx/sites-available/django-project
时找到了解决方案。但我需要在/etc/nginx/nginx.conf
Nginx 的全局设置中添加以下行。我添加的行是:我有一个小型网站托管,上面的设置就足够了。但其他人可能会根据自己的需要进行设置。