How to fix upstream timed out (110: Connection timed out) error in Nginx

When you come across "Upstream timed out (110: Connection timed out)" error in your Nginx log:

[error] upstream timed out (110: Connection timed out) while reading response header from upstream, 
client: xxx.xxx.xxx.xxx, server: howtounix.info, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8080", host: "howtounix.info", referrer: "requested_url"

That means it takes your web server more than 60 seconds to respond. To solve this problem in nginx.conf change the value of proxy_read_timeout directive. This directive determines how long nginx will wait to get the response to a request. By default it's 60 seconds. Change it to 300 seconds:

server {
    listen       80;
    server_name  howtounix.info;
 
    location / {
        ...
        proxy_read_timeout 300;
        ...
    }
    ...
}

This should fix the problem.







beer
2012-10-09 16:52:08
you crazy? 5minuts time out o_O
Sergey
2012-10-09 16:53:31
Why not?
yoba
2012-10-09 16:54:17
nice advice thanks, now my apaches are allways in "server reached MaxClients"
Sergey
2012-10-09 16:58:43
Then you probably have a problem on application side and you need to fix this instead of tuning timeouts. You only need to touch timeouts if you know that your application needs it (i.e. uploading huge files or launching heavy processing scripts/parsers, etc)
2012-11-26 01:25:23
Why would you tie up nginx with a client request for 5 min!! You're just asking for an easy way to DDoS your site. Set sane timeouts. If your server doesn't respond in 5 seconds, you have a much bigger issue.
unixowl
2012-11-26 05:19:43
The previous comment answers to your question
recarv
2013-04-27 18:01:18
Or make it location specific timeout if you know that one URL needs longer to process, but don't put that in the root location block. For example - we have a reporting url that takes a long time - so we set this url specifically with a different timeout - that way the DDoS is limited (the attacker would have to know to hit that url).
2013-06-12 22:51:28
Call me crazy, but the ddos talk is unwarranted. I can send 10k connections to your server in 30s just as easily as I can send them in 300s. If you're worried about dns, you should be looking at a thorttling setting that makes sense.
Guest
2014-08-04 19:09:53
this "solution" is almost as awesome as the one i saw saying the way to fix php errors is to turn off error logging
Trex
2014-09-22 16:32:51
Actually this solution was useful to me as I'm using Nginx only as an http load balancer in front of a bunch of internal corporate J2EE interactive reporting apps that can take quite some time to process their requests.
Yuan Yuan
2014-10-03 10:18:04
Thank you all upstairs, you all spoke out what I want to ask
Ivan
2014-11-04 22:10:43
Does not work for me.
Jimbo
2014-11-23 13:19:05
Does not work for me either.

Got a comment?
Name (optional):
Comment
Anti-Bot:captcha =
 
 
Copyright © 2012-2013 HowToUnix - *nix Howtos and Tutorials
All Rights Reserved.