November 24, 2023

How to Fix the 502 Bad Gateway Error on Plesk Server

How to Fix the 502 Bad Gateway Error on Plesk Server

Symptoms

If your website hosted on a Plesk server is showing a “502 Bad Gateway” error, you may also encounter these error messages in the log files:

        [error] 14790#0: *188 upstream sent too big header while reading response header from upstream, client: 203.0.113.2, server: subdomain.example.com, request: "POST /admin_catalog.php HTTP/1.1", upstream: "http://10.0.0.1:7080/admin_catalog.php", host: "subdomain.example.com", referrer: "http://subdomain.example.com/admin_catalog.php"
        [error] 707#0: *2016153 FastCGI sent in stderr: "PHP message: Error checking in buffer: The buffer you checked in was not checked out" while reading upstream, client: 203.0.113.2, server: example.com, request: "POST /wp-admin/admin-ajax.php HTTP/1.1", upstream: "fastcgi://unix:///var/www/vhosts/system/example.com/php-fpm.sock:", host:"example.com", referrer: "https://example.com/wp-admin/post-new.php?wp-post-new-reload=true"
        2020/04/27 20:07:05 [error] 4966#0: *39052 proxy_buffer_size x is not enough for cache key, it should be increased to at least xx, client: *****, server: example.com, request: "GET /wp-admin/admin-post.php.."

Cause

The “502 Bad Gateway” error occurs when a request cannot be processed by the proxy server due to insufficient buffer size.

Resolution

For One or Few Domains

  1. Log into Plesk.
  2. Go to Domains > example.com > PHP Settings and check the selected PHP handler (the field “run PHP as”).
  3. Go to Domains > example.com > Apache & nginx Settings.
  4. Scroll down to the “Additional nginx directives” field and set the following parameters based on the PHP handler used:
    • For PHP handler FPM application served by Nginx and disabled Proxy Mode:
                          fastcgi_buffers 8 16k;
                          fastcgi_buffer_size 32k;
      
    • For other cases:
                          proxy_buffers 8 16k;
                          proxy_buffer_size 32k;
      
  5. You can increase these values if needed to accommodate larger headers.

For All Domains

    1. Connect to the server using SSH.
    2. Open the file /etc/nginx/nginx.conf for editing.
    3. Increase the following parameters in the section http:
            proxy_buffers 8 16k;
            proxy_buffer_size 32k;
            fastcgi_buffers 8 16k;
            fastcgi_buffer_size 32k;
  1. Restart Nginx to apply changes:
                    # service nginx restart
    
  2. Increase values of these parameters if needed.

Conclusion

By following the steps outlined in this tutorial, you can resolve the “502 Bad Gateway” error on your Plesk server and ensure your websites operate smoothly. Properly configuring buffer sizes is essential for maintaining optimal website performance.

© 2023 seolucas.com

Share this post:
Facebook
Twitter
LinkedIn
WhatsApp

Discover more articles