Articles in this section

Some websites are not accessible with "502 Bad Gateway" or "504 Gateway Time-out": (11: Resource temporarily unavailable) while connecting to upstream

Plesk for Linux kb: technical

Applicable to:

  • Plesk for Linux

Symptoms

  • Websites are not accessible, displaying a "502 Bad Gateway" or "504 Gateway Time-out" error.
  • The following error message appears in the domain's proxy error log file (/var/www/vhosts/system/example.com/logs/proxy_error_log):

    CONFIG_TEXT: [error] 106799#0: *613 connect() to unix:///var/www/vhosts/system/example.com/php-fpm.sock failed (11: Resource temporarily unavailable) while connecting to upstream, client: 203.0.113.2, server:example.com, request: "HEAD / HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/example.com/php-fpm.sock:", host: "www.example.com"

  • The Apache error log (/var/www/vhosts/system/example.com/logs/error_log) may show a timeout error:

    CONFIG_TEXT: [proxy_fcgi:error] [pid 23830] (70007) The timeout specified has expired: [client 203.0.113.2:47798] AH01075: Error dispatching request to :

  • The PHP-FPM error log (/var/log/plesk-phpXX-fpm/error.log) may contain warnings indicating that the process limit has been reached:

    CONFIG_TEXT: WARNING: [pool example.com] server reached max_children setting (10), consider raising it

  • The socket file exists and is not duplicated:

    CONFIG_TEXT: # ls -la /var/www/vhosts/system/example.com/php-fpm.sock
    srw-rw----. 1 root psaserv 0 May 27 03:43 /var/www/vhosts/system/example.com/php-fpm.sock

Cause

PHP-FPM processes are hung or completely exhausted. This is typically caused by the pm.max_children limit being reached due to heavy traffic, or script execution timeouts caused by faulty website code/plugins.

Resolution

Temporary Workaround

 

Restarting the hung PHP-FPM service will immediately bring the website back online.

 

In Plesk:

  1. Log in to Plesk.
  2. Determine which PHP-FPM service handles the domain by navigating to Domains example.com PHP Settings.
  3. Go to Tools & Settings Services Management.
  4. Click the Restart button next to the corresponding PHP-FPM service (e.g., PHP 80 FPM).

 

Alternative method via SSH:

  1. Connect to the server via SSH.
  2. Restart the specific PHP-FPM service (replace XX with the actual PHP version used by the domain, e.g., 80 for PHP 8.0):

    # systemctl restart plesk-phpXX-fpm

Permanent Fix

To prevent the issue from reoccurring, address the root cause of the hung processes:

  • Increase process limits: If the server has sufficient RAM and CPU resources, consider increasing the pm.max_children limit for the domain's PHP-FPM pool.
  • Investigate website code: If the issue persists, review the domain's PHP error logs to identify any faulty plugins, loops, or scripts that are failing to open streams or causing caching timeouts, and consult a website developer to optimize the code.
Was this article helpful?

Comments

0 comments

Please sign in to leave a comment.