Websites hosted on Plesk server often results with 502 Bad Gateway

Introduction

Most importantly, websites are unavailable and often result in 502 Bad gateway in the Plesk server.

Root cause

A request cannot be processed by the proxy server because of insufficient buffer size.

In the log files /var/log/nginx/error.log

Consequently, in the following error message can be found “upstream sent too big header while reading response header”

Sample error log:

[error] 13690#0: *244 upstream sent too big header while reading response header from upstream, client: x.x.x.x, server: subdomain.example.com, request: "POST /admin_catalog.php HTTP/1.1", upstream: "http://x.x.x.x/admin_catalog.php", host: "subdomain.example.com", referrer: "http://subdomain.example.com/admin_catalog.php"

Solution

For one or two domains [In specific]

  1. Log in to Plesk panel, firstly.
  2. Go to Domains > zzz.com > PHP Settings and check the selected PHP handler (the field run PHP as).
  3. Go to Domains > zzz.com > Apache & nginx Settings, scroll down to the field Additional nginx directives.

    And also set the following parameters in accordance with the used PHP handler:
    • For PHP handler FPM application served by Nginx:

      fastcgi_buffers 8 16k;
      fastcgi_buffer_size 32k;
  4. For other PHP handlers:

    proxy_buffers 8 16k;
    proxy_buffer_size 32k;

Above all, increase the values of these parameters if it is needed.

For all the domains in Plesk

  1. Secondly, connect to the server using SSH.
  2. Open and edit the file /etc/nginx/nginx.conf 
  3. For instance, increase the following parameters in the section http {:

    proxy_buffers 8 16k;
    proxy_buffer_size 32k; 
    fastcgi_buffers 8 16k; 
    fastcgi_buffer_size 32k;
  4. Then, restart nginx to apply changes:

    # service nginx restart

Thanks for using pheonix solutions.

Leave a Reply