Nginx upstream timed out

Upstream timed out (110: Connection timed out) while reading response header from upstream, that was the exact message I saw on my system logs today.

I knew I already fixed this many times, but haven’t any documentation about it, that’s why today I’m writing this post, to have a definitive and fast way to search for Nginx upstream timed out error if it happens again in the future.

This error can be seen and searched over the internet in the following ways:

  • nginx upstream timed out error and fix
  • upstream timed out (110: Connection timed out) while reading response header from upstream
  • nginx error while reading response header from upstream

How can I fix Nginx upstream timed out error?

This nginx upstream timed out error was found on this same plain box that I use for nixcp.com website. After investigating I found that it was caused by a low value on my php-ftpm configuration.

In order to fix it I just altered the fastcgi_read_timeout variable, this is my current configuration:

location ~* .php$ {
      include fastcgi_params;
      fastcgi_index index.php;
      fastcgi_read_timeout 160;
      fastcgi_pass 127.0.0.1:9001;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

Solution for reverse proxy on cPanel or plain servers

If you have a different configuration like a reverse proxy (which can be done usign Nginx plugins for cPanel), you can alter the timeout variables too by setting a higher value for proxy_read_timeout directive.

Just add this directive or modify to a higher value inside your nginx vhost configuration, as you see below.

location / {
...
...
proxy_read_timeout 160;
...
...
}

For both solutions restart Nginx to apply changes:

service nginx restart

The propossed value of “160” is a value that worked for me, you may need to increase it or decrease it depending on how your apps run.
That’s all, at this time you should know how to fix this common Nginx upstream timed out (110: Connection timed out) while reading response header from upstream error.

Do you know other ways to fix this? Please share your knowledge with us.

Further reading:

About the Author: Santiago Borges

Experienced Sr. Linux SysAdmin and Web Technologist, passionate about building tools, automating processes, fixing server issues, troubleshooting, securing and optimizing high traffic websites.

Leave a Reply

Your email address will not be published. Required fields are marked *