upstream split a header line in FastCGI records

matrix nginx-forum at
Mon Aug 3 23:31:37 MSD 2009


For the past 10 hours I have been trying to find out why my application sometimes generates a "502 Bad Gateway" error and sometimes do not, even though the page output should be nearly identical. The error is described by nginx as "upstream prematurely closed connection while reading response header from upstream" without debug and as "upstream split a header line in FastCGI records" with debug.

This only happens when I'm using FirePHP, a debugging class for PHP, which sends information to browser using headers. It would appear that it only happens when the amount of output from FirePHP reaches a certain value that the error happens, as I don't get any errors if FirePHP outputs only a small amount of debug information.

The error still happens if I create a new PHP script with just FirePHP loaded and use it to output a lot of random strings (preset in script). Yet, the error still only happens sometimes (about 50% chance).

I have tried the latest versions of all 3 branches of nginx (legacy, stable and development) with the same results. PHP is 5.3.0, with php-fpm (spawn-fcgi causes same error) and unix sockets as the link between PHP and nginx (TCP connection causes same error).

My fastcgi settings in nginx are:

fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on

I've ran nginx in debug mode and got logs of a good page and of a bad page:
Bad: (things go bad at line 250)

I hereby request help. Is it a nginx problem or is it something else?

Thank you,

Posted at Nginx Forum:,4704,4704#msg-4704

More information about the nginx mailing list