我使用nginx作为反向代理,以便能够访问我的Django并提供静态文件。我的Django正在使用gunicorn。
我有一个端点,允许用户下载csv文件。我按照这里的说明,流大型CSV文件:https://docs.djangoproject.com/en/2.2/howto/outputting-csv/
下面是nginx配置:
upstream docker-api {
server api;
}
server {
listen 443 ssl;
server_name xxxx.com;
ssl_certificate /path/to/fullchain.pem;
ssl_certificate_key /path/to//privkey.pem;
include /path/to/options-ssl-nginx.conf;
ssl_dhparam /path/to/ssl-dhparams.pem;
location /static {
autoindex on;
alias /static/;
}
location /uploads {
autoindex on;
alias /uploads/;
}
location / {
proxy_pass http://docker-api;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
这是我用来启动我的gunicorn服务器的命令:
gunicorn my_api.wsgi -b 0.0.0.0:80 --enable-stdio-inheritance -w 2 -t 180 -k gevent
当我尝试下载文件时,Gunicorn总是在3分钟后超时请求。它不应该超时流http响应。
发布于 2019-06-01 03:29:33
问题是你的命令。
让我们来看看:
金角角my_api.wsgi -b 0.0.0.0:80 -启用-stdio-继承-w 2 -t 180 -k gevent
-t
在你的timeout
命令中代表timeout
,它以秒为单位,而你的工匠超时是因为你已经将超时设置为180秒(3分钟)。
当我尝试下载文件时,Gunicorn总是在3分钟后超时请求。
为了解决这个问题,您可以简单地增加超时,例如,下面的gunicorn命令将超时设置为5分钟:
my_api.wsgi -b 0.0.0.0:80 -启用-stdio-继承-w 2 -t 300 -k gevent
有关更多信息,请查看文档:http://docs.gunicorn.org/en/stable/settings.html#timeout
发布于 2020-03-23 08:04:56
此错误通常由以下两种情况引发:
- first, go to the file you created in the following directory (in my case named `myproject`)
$ nano /etc/nginx/sites现有/myproject
location /
部分应该如下所示(请注意超时部分):
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
}
$ systemctl启动nginx
$ nano /etc/systemd/system/gunicorn.service
--timeout 300
添加到[service]
部分下的文件中。要获得更多帮助,您可以从链接查看整个文件
[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target
[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/myprojectdir
ExecStart=/home/sammy/myprojectdir/myprojectenv/bin/gunicorn \
--access-logfile - \
--workers 3 \
--timeout 300 \
--bind unix:/run/gunicorn.sock \
myproject.wsgi:application
[Install]
WantedBy=multi-user.target
$ systemctl守护进程-重新加载 $ systemctl重新启动gunicorn.socket gunicorn.service
https://stackoverflow.com/questions/56402550
复制相似问题