Uncategorized

connect() to unix:/run/php/php7.4-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream

You have magento >=2.3.5 running in nginx server and your customer might face 502 error from time to time. Not always but from time to time. You check your error log for nginx and find this “4746#4746: *1502011 connect() to unix:/run/php/php7.4-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream” .

So what you do in this case?

When your traffic is high php fpm does not responds to the request sent by nginx and since nginx doesnt get a response it throws an 502 error. So solution for this is you can use TCP sockets instead of php fpm sockets.

This is how you do it:

step 1 : Go to fpm pool configuration. path can be /etc/php/7.4/fpm/pool.d/www.conf

step 2: comment ;listen = /run/php/php7.4-fpm.sock and add listen=127.0.0.1:9000; for added security you can comment out listen.allowed_clients = 127.0.0.1

step 3: Go to your site nginx config in /etc/nginx/sites-available and add this

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass 127.0.0.1:9000;
}

if you are using fastcgi_backend then update that also with

upstream fastcgi_backend {
server 127.0.0.1:9000;
}

 

After doing this restart your nginx server and php-fpm service.

You will see after this configuration change you will that the 502 error is gone.

 4,438 total views

Leave a Reply

Your email address will not be published. Required fields are marked *