×


Nginx upstream timed out error - Fix it Now ?

Nginx upstream timeout error (110: Connection timed out) appears when nginx is not able to receive an answer from the webserver.

Basically, this error happens when PHP FPM service  of the Nginx web server is crashing.

Here at Ibmi Media, as part of our Server Management Services, we regularly help our Customers to resolve related Nginx errors.

In this context, we shall look into methods to fix this Nginx error.


Nature of Nginx upstream timed out error

The upstream timeout error generally triggers when the upstream takes too much to answer the request and NGINX thinks the upstream already failed in processing the request.

Some of the common reasons for this error include:

1. Server resource usage

2. PHP memory limits

3. Server software timeouts


How to fix Nginx upstream timed out error?

1. Server resource usage

One of the most common reasons for this error is server resource usage. Often heavy load makes the server slow to respond to requests.

When it takes too much time to respond, in a reverse proxy setup Nginx thinks that the request already failed.

We already have some articles discussing the steps to troubleshoot server load here.

We also make sure that there is enough RAM on the server. 

To check that they use the top, htop or free -m commands.

In addition, we also suggest optimizing the website by installing a good caching plugin. 

This helps to reduce the overall resource usage on the server.


2. PHP memory limits

At times, this error could be related only to specific PHP codes.  Our Support Engineers cross-check the PHP FPM error log in such cases for a more detailed analysis of the error.

Sometimes, PHP would be using too much RAM and the PHP FPM process gets killed. In such cases, we would recommend to make sure that the PHP memory limit is not too high compared to the actual available memory on the Droplet.

For example, if you have 1GB of RAM available your PHP memory limit should not be more than 64MB.


3. Server software timeouts

Nginx upstream errors can also occur when a web server takes more time to complete the request.

By that time, the caching server will reach its timeout values(timeout for the connection between proxy and upstream server).

Slow queries can lead to such problems.

We will fine tune the following Nginx timeout values in the Nginx configuration file:

proxy_connect_timeout 1200s;
proxy_send_timeout 1200s;
proxy_read_timeout 1200s;
fastcgi_send_timeout 1200s;
fastcgi_read_timeout 1200s;

Once the timeout values are added, need to reload Nginx to save these parameters.


[Need urgent assistance in fixing Nginx errors? We can help you. ]


Conclusion

This article covers methods to resolve Nginx upstream timed out error. Basically, this error happens as a result of server resource usage and software timeouts.

A possible issue here could be that PHP is using too much RAM and the PHP FPM process gets killed. 


Therefore, do the following to fix this nginx error:

1. Make sure that there is enough RAM on the server, to check that you could use the top, htop or free -m commands.

2. Make sure that the PHP memory limit is not too high compared to the actual available memory on the Droplet. 

For example if you have 1GB of RAM available your PHP memory limit should not be more than 64MB otherwise only a few processes could consume all of your memory.

3. Optimize your website by installing a good caching plugin, that way you would reduce the overall resource usage on the server.

4. Delete any plugins that are not being used. Generally speaking, it is always recommended to try and keep the number of your plugins as low as possible.

5. Consider using a CDN like Cloudflare, that way it would offload some of the heavy liftings from your Droplet.