简体   繁体   English

110:连接超时(Nginx/Gunicorn)

[英]110: Connection timed out (Nginx/Gunicorn)

I'm running django on gunicorn+nginx.我在 gunicorn+nginx 上运行 django。 I'm facing a problem with file uploads.我在上传文件时遇到问题。 Actually uploads are working fine but gunicorn times out thus causing this in nginx:实际上上传工作正常,但 gunicorn 超时,从而在 nginx 中导致这种情况:

2011/07/25 12:13:47 [error] 15169#0: *2317 upstream timed out (110: Connection timed out) while reading response header from upstream, client: IP-ADDRESS, server: SERVER, request: "GET /photos/events/event/25 HTTP/1.1", upstream: "http://127.0.0.1:29000/photos/events/event/25", host: "HOST", referrer: "REFERER_ADDRESS"

If I refresh the page, I can see all the photos are uploaded just fine.如果我刷新页面,我可以看到所有照片都上传得很好。 The problem is that it causes a timeout thus giving the impression that upload did not work.问题是它会导致超时,从而给人一种上传不起作用的印象。

here is my gunicorn conf:这是我的 gunicorn conf:

bind = "127.0.0.1:29000"
logfile = "/path/to/logs/gunicorn.log"
workers = 3

I tried changing timeout but it didn't work.我尝试更改超时,但没有用。

You could try upgrading the timeout for your proxy pass in Nginx by adding:您可以尝试通过添加以下内容来升级 Nginx 中代理传递的超时:

proxy_connect_timeout 75s;
proxy_read_timeout 300s;

on /var/nginx/sites-available/[site-config] or /var/nginx/nginx.conf if you want to increase the timeout limite on all sites served by nginx.在 /var/nginx/sites-available/[site-config] 或 /var/nginx/nginx.conf 上,如果您想增加 nginx 服务的所有站点的超时限制。

You must add --timeout 300 as well to your gunicorn process/config.您还必须将--timeout 300添加到您的 gunicorn 进程/配置中。

This solved my problems in the past with bigger uploads.这解决了我过去上传更大的问题。

This is not an nginx timeout, but probably a Gunicorn timeout.这不是 nginx 超时,而可能是 Gunicorn 超时。 Gunicorn defaults to a 30 second timeout. Gunicorn 默认为 30 秒超时。

In general, you should fix this by not having an endpoint that takes longer than 30 seconds to return, but if it is a seldom used endpoint, you can also just increase the gunicorn timeout.通常,您应该通过不让端点返回时间超过 30 秒来解决此问题,但如果它是一个很少使用的端点,您也可以增加 gunicorn 超时。

If you do this, you should probably also increase the number of gunicorn worker processes as well.如果您这样做,您可能还应该增加 gunicorn 工作进程的数量。

To increase the timeout and workers for gunicorn, you can add the following command-line options on start:要增加 gunicorn 的超时和工作人员,您可以在启动时添加以下命令行选项:

gunicorn --timeout 120 --workers <NUMBER OF WORKER YOU WANT>

We had the same problem using Django+nginx+gunicorn.我们在使用 Django+nginx+gunicorn 时遇到了同样的问题。 From Gunicorn documentation we have configured the graceful-timeout that made almost no difference.从 Gunicorn 文档中,我们配置了几乎没有区别的优雅超时。

After some testings, we found the solution, the parameter to configure is: timeout (And not graceful timeout).经过一些测试,我们找到了解决方案,配置的参数是:超时(而不是优雅超时)。 It works like a clock..它像时钟一样工作..

So, Do:所以,做:

1) open the gunicorn configuration file 1)打开gunicorn配置文件

2) set the TIMEOUT to what ever you need - the value is in seconds 2) 将 TIMEOUT 设置为您需要的值 - 值以秒为单位

NUM_WORKERS=3
TIMEOUT=120

exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--timeout $TIMEOUT \
--log-level=debug \
--bind=127.0.0.1:9000 \
--pid=$PIDFILE

如果您在 Nginx 中使用反向代理并使用 Gunicorn 运行 Django 应用程序,请尝试从默认值调整 Gunicorn 超时参数和 proxy_read_timeout 参数。

This might help someone with similar problem.这可能会帮助有类似问题的人。

I was getting timeout error from nginx and gunicorn on my Django application.我在我的 Django 应用程序上收到来自 nginx 和 gunicorn 的超时错误。 Since I was getting the timeout error from nginx, I couldn't see the real error from Django.因为我从 nginx 收到超时错误,所以我看不到 Django 的真正错误。 After adding the new timeout like fijter suggested.在添加了像 fijter 建议的新超时之后。 I could see that the error was in the settings.py file.我可以看到错误在 settings.py 文件中。

If you set the DEBUG to False, and didn't add the domain name in the ALLOWED_HOSTS you might get this error.如果您将 DEBUG 设置为 False,并且没有在 ALLOWED_HOSTS 中添加域名,您可能会收到此错误。

I just added the domain in the ALLOWED_HOSTS in settings.py and the error was gone.我刚刚在 settings.py 的 ALLOWED_HOSTS 中添加了域,错误消失了。

Very simple solution!非常简单的解决方案!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 连接到上游时上游超时(110:连接超时) - upstream timed out (110: Connection timed out) while connecting to upstream ERR_CONNECTION_TIMED_OUT 同时使用 AWS 弹性豆茎部署 django(使用 nginx + gunicorn) - ERR_CONNECTION_TIMED_OUT while deploying django using AWS elastic beanstalk(with nginx + gunicorn) * 10上游超时(110:连接超时),同时使用uwsgi从上游读取响应头 - *10 upstream timed out (110: Connection timed out) while reading response header from upstream with uwsgi heroku 中的 Django Redis 连接错误:写入套接字时出现错误 110。 连接超时 - Django Redis connection error in heroku: Error 110 while writing to socket. Connection timed out GAE内部服务器错误URLError: <urlopen error ftp error: [Errno 110] Connection timed out> - GAE Internal Server Error URLError: <urlopen error ftp error: [Errno 110] Connection timed out> 连接被拒绝 django gunicorn nginx - connection refused django gunicorn nginx nginx,gunicorn和django超时 - nginx, gunicorn and django timing out nginx / gunicorn连接挂60秒 - nginx/gunicorn connection hanging for 60 seconds POST&gt;连接超时Django - POST > Connection timed out Django Django,nginx和+ gunicorn:提供媒体文件时连接被拒绝 - Django, nginx, + gunicorn: connection refused when serving media files
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM