504 Gateway Time-out – Nginx

You run a task and Nginx throws the following error:

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

This can be truly annoying and at times difficult to pinpoint.

To fix this error, create a new file called limits.conf at the location /etc/nginx/conf.d and copy the following lines of code into it. This is assuming that conf.d is set to be included in nginx.conf.

proxy_connect_timeout       600;
proxy_send_timeout          600;
proxy_read_timeout          600;
send_timeout                600;

This effectively takes these limits up to 5 minutes. Restart Nginx and run your task again to see if it throws the error again

service nginx restart

If you still get a timeout error then try doubling the values above and tweak them until you get it right.