Nginx – Is it possible to display a custom error page for 110: Connection timed out

nginxphp-fpm

We are seeing the following error in our nginx logs. The error is well documented but we have not yet figured out what is causing it. In the meantime, is it possible to display a custom error page when this error occurs? In the same way that we can have error_page directive for http 500 errors.

7252#0: *2711 upstream timed out (110: Connection timed out) while connecting to upstream, client: x.x.x.x, server: domain.com, request: "GET /a_page.php?etc.... HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "thehost.com", referrer: "http://thereferrer.com/"

Best Answer

I don't think the 110 error is actually what is thrown back to the client and is more likely to be a 504 gateway time out. You can define a custom error page and enter corresponding error numbers for it to render in your nginx config. If you already have this in your nginx config, just add in 504.

Site wide:

server {
    listen 80;
    error_page  504  /errorpage.htm;

In regards to the actual problem, it's likely fastcgi is taking too long to return data to nginx. Try increasing the fastcgi_read_timeout in nginx.conf. Otherwise, make sure fastcgi is running properly.