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

October 4, 2019 247 views
MySQL Docker Nginx PHP

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 )

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.

Have another answer? Share your knowledge.