nginx and php header + flush

Maxim Dounin mdounin at mdounin.ru
Fri Sep 2 11:57:16 UTC 2011


Hello!

On Fri, Sep 02, 2011 at 07:50:32AM -0400, ykse wrote:

> Hello guys,
> I've got strange problem with my webserver. I've got nginx and apache
> with php as backend www server, and now when I tryin to run this code
> ->
> 
> <?php
> 
>     header('HTTP/1.x 404 Not Found');
>     echo "sometext";
>     flush();
> ?>
> 
> ( it's on apache )
> 
> nginx returns something like this ->
> 
> 
> 8 sometext 0
> 
> 
> As you can see it's returns some numbers, but why ? When I'm openning
> same script directly from apache it's returns only "sometext" without
> any numbers.
> 
> 
> Do you have any idea why nginx returns this numbers ?

These numbers are from chunked encoding incorrectly sent by apache 
to nginx.  This behaviour is the result of a bug in apache's 
mod_php which forces HTTP/1.1 reply despite the fact client 
(nginx) uses HTTP/1.0 in request.

To fix this, just change

    header('HTTP/1.1 ...');

to

    header('HTTP/1.0 ...');

in your php code, or use "SetEnv downgrade-1.0" in apache config 
as a workaround if changing code is problematic for some reason.  
See [1] for more information.

[1] http://mailman.nginx.org/pipermail/nginx/2011-August/028508.html

Maxim Dounin



More information about the nginx mailing list