Nginx Connection timed out while connecting to upstream on Docker-ized server during spike in requests

Posted October 4, 2019 20.9k views

I’ve a dockerized server on DigitalOcean that have problems serving requests when spike traffic happens. This is the architecture:

Nginx-proxy <-> Nginx <-> PHP-FPM <-> MySQL

These a proxy wide parameters:

client_max_body_size 100M;
proxy_connect_timeout 3000;
proxy_send_timeout 3000;
proxy_read_timeout 3000;
send_timeout 3000;

And fastcgi inside locations file:

fastcgi_read_timeout 3000;

During spike logs:
Proxy: correctly responds but with code 499/0
Nginx: upstream timed out (110: Connection timed out) while connecting to upstream)

(Reposting question originally asked by: @tech585b88c5b25f22dbb1db14 )

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

Hello, @aha

Can you also check the logs to see if the Nginx workers have been exceeded? You can see if the values for workerconnections and workerprocesses is not set too low.

From my previous experience when I’m receiving the exact same error it’s related to the php-fpm. You can check the fpm pool is not exceeded as well. It’s really helpful to examine the fpm logs as well.

When the issue happens you can restart the fpm service to see if it will solve the issue. Then you will know that you must tweak the PHP-FPM pool configuration.

Let me know how it goes.