我正在尝试使用Nginx + uwsgi运行Django应用程序,但是加载一分钟后我收到了504 Gateway Time-out
。
我的应用在搜索多个网站上的特定内容时需要花费时间来做所需的事情。
我的nginx conf是下一个:
upstream uwsgi {
server 127.0.0.1:8000;
}
server {
listen 80;
server_name server_ip;
root /opt/emails/subscriptions;
index index.html index.htm index.php;
location /emailsproject/ {
root /opt/emails/subscriptions/;
}
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://uwsgi;
proxy_set_header Host $http_host;
uwsgi_read_timeout 18000;
}
}
我的uwsgi脚本:
description "uWSGI server"
env PYTHONPATH=/opt/emails/subscriptions
env DJANGO_SETTINGS_MODULE=emailsproject.settings
start on runlevel [2345]
stop on runlevel [!2345]
respawn
exec uwsgi_python --http-socket 127.0.0.1:8000 -p 4 --wsgi-file /opt/emails/subscriptions/emailsproject/wsgi.py
我的nginx在error.log中给我以下错误消息:
2015/09/28 02:15:57 [error] 4450#0: *19 upstream timed out (110: Connection timed out) while reading response header from upstream, client: 37.235.53.246, server: my_server_ip, request: "POST /home/ HTTP/1.1", upstream: "http://127.0.0.1:8000/home/", host: "my_server_ip", referrer: "http://my_server_ip/home/"
有谁对我如何摆脱这个想法有任何想法?我已经尝试了大量的stackoverflows解决方案,但是没有一个对我有用。
最佳答案
如果其内部任务需要太多时间来处理,请使用celery运行该任务。
http://docs.celeryproject.org/en/latest/userguide/tasks.html
如果它不是纯粹的内部任务,例如:-上传大文件,则将Nginx client_body_timeout
增加到大于60s
。
这是因为Nginx配置中的默认超时。编辑Nginx虚拟主机文件
并在 server{}
部分中添加以下行。
http://nginx.org/en/docs/http/ngx_http_core_module.html#client_body_timeout
# defualt is 60 seconds, For a 300 second timeout.
client_body_timeout 300s;
编辑:
还需要
uwsgi_read_timeout 300s;
。但它已经在您的配置中。
关于django - 504网关超时uwsgi + nginx Django应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32816975/