Nginx “upstream timeout (110: Connection timed out)” error appears when nginx is not able to receive an answer from the webserver.
As a part of our Server Management Services, Our Support Engineers helps webmasters fix Nginx-related errors regularly.
Let us today discuss the possible reasons and fixes for this error.
What causes 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. A typical error message looks like this:
Some of the common reasons for this error include:
- Server resource usage
- PHP memory limits
- Server software timeouts
Let us now discuss how our Support Engineers fix this error in each of the cases.
How to fix Nginx “upstream timed out” error
Server resource usage
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.
Our Support Engineers 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.
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.
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.
Our Support Engineers 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.
Conclusion
In short, Nginx upstream timed out triggers due to a number of reasons that include server resource usage and software timeouts. Today, we saw how our Support Engineers fix this error.
0 Comments