Nginx: upstream timed out (110: Connection timed out)

Error 110: Connection timed out while reading response header from upstream

Sometimes a Nginx web server seems to load pages with php code with a lot of xml parsing really slowly. Often it doesn’t load or connection times out. This will be seen more on pages where the php code parses through large xml files and outputs data only when all the parsing is complete. The Nginx web server times out before php returns output.

We have to make the Nginx web server wait more before giving up on the upstream.

This is a typical error I get:

upstream timed out (110: Connection timed out) while reading response header from upstream


connect() to unix:/var/run/php5-fpm.sock failed (2: No such file or directory) while connecting to upstream

and such. The second one is inexplicable, since everything is working when not timing out, but I have often seen these two together.

The fix that works is increasing the timeout.

In the server configuration /etc/nginx/nginx.conf on Ubuntu/Debian, in the http {....} block, add the line (or edit the commented out line)
fastcgi_read_timeout 300s;

Restart the Nginx web server (as root or with sudo).
service nginx restart

There should be an immediate improvement when parsing large xml files. If you are still having problems, raise the number till resolved.

English: Nginx Logo Español: Logo de Nginx

English: Nginx web server Logo Español: Logo de Nginx (Photo credit: Wikipedia)

Enhanced by Zemanta

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Current ye@r *