[Nginx Standalone] Error 500 "upstream sent too big header" turns into 502 Bad Gateway when increasing buffers

Hi ,

I am facing a persistent issue on a HestiaCP (Nginx Standalone + PHP-FPM) setup when trying to connect the official Bunny.net WordPress plugin.

The Scenario: The plugin attempts to link the account via a GET request containing a very long API Key in the URL parameter.

The Problem:

  1. Default Configuration: Nginx throws an Error 500. The error log shows: upstream sent too big header while reading response header from upstream, request: "GET /wp-admin/admin.php?page=bunnycdn&apiKey=xxxxxxxx..."

  2. Attempted Fix: I tried to increase the FastCGI buffers in the Nginx configuration (both in nginx.conf directly and via custom Web Templates). I added the following directive inside the PHP location block:

    Nginx

    location ~ [^/]\.php(/|$) {
        ...
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
        ...
    }
    
    
  3. The Result: As soon as I increase the buffers to fix the Error 500, the server immediately throws an Error 502 Bad Gateway.

    • I have tried “middle ground” values (64k/128k). Result: 502.

    • I have tried increasing timeouts (fastcgi_read_timeout 300, etc). Result: 502.

    • I verified that the PHP-FPM service (tested on PHP 8.2, 8.3, and 8.4) is running.

    • The php-fpm.log does not show any crash or specific error when the 502 happens.

    • If I revert the buffers to default, the 502 disappears, and the Error 500 (headers too big) returns.

Environment:

  • HestiaCP Version: (Latest)

  • OS: Ubuntu

  • Web Server: Nginx only (No Apache)

  • PHP-FPM: Tested on 8.2, 8.3, 8.4.

It seems like increasing the buffers causes PHP-FPM to hang or Nginx to fail the handshake immediately.

Does anyone know the correct buffer configuration for HestiaCP Nginx templates to handle large headers without causing a 502?

Thanks in advance.

Try modifying these directives in /etc/nginx/nginx.conf (you should back up the conf first):

client_header_buffer_size       4k;
large_client_header_buffers     4 64k;

fastcgi_buffer_size             128k;
fastcgi_buffers                 4 256k;
fastcgi_busy_buffers_size       256k;
fastcgi_temp_file_write_size    256k;

proxy_buffer_size               128k;
proxy_buffers                   4 256k;
proxy_busy_buffers_size         256k;

Restart Nginx and try again.

Note: you should remove those directives from the templates.

Thank you for your help. I backed up my configuration, applied the suggested values ​​to the main /etc/nginx/nginx.conf file, and cleaned up the web templates.

Unfortunately, it’s now throwing a 502 error: “Unable to connect to origin server.”

However, I discovered something interesting: I tried installing the exact same plugin on a different WordPress site hosted on this same server, and it worked perfectly there.

Since they share the same global Nginx configuration and PHP version, I am confused why one triggers the 502 and the other does not