Only 64k sent when the first upstream failed in fastcgi_pass

Jing Ye yejingx at gmail.com
Tue Jun 17 15:50:19 UTC 2014


Hello all,

I have encountered the following possible bug in Nginx when using the
fastcgi_pass directive to put a file larger than 64k. I’m not sure if this
is a bug or I missed something in the config file.

My nginx version is 1.5.12, and the problem remains when i switched to the
newest 1.7.2.


Here is my nginx.conf file,

    upstream *api.php.com <http://api.php.com>* {
            server 127.0.0.1:9902 max_fails=3 fail_timeout=30s;
            server 127.0.0.1:9901 max_fails=3 fail_timeout=30s;
    }
    server {
        listen       8080;
        server_name  localhost;
        location ~ \.php$ {
            root           html;
            fastcgi_pass   *api.php.com <http://api.php.com>*;
            fastcgi_param  SCRIPT_FILENAME
/usr/local/nginx/html/$fastcgi_script_name;
            fastcgi_index  index.php;
            include        fastcgi_params;
        }



And the index.php file,

<?php
/* simplify get the request body and print its length. */
$raw_post_data = file_get_contents('php://input', 'r');
print(strlen($raw_post_data));
sleep(3);               /* waiting for the server to be reset after 1
second  */
?>


We need two php-fpm servers listen on port 9901 and 9902, and importantly,
the server listen on 9902 should be somehow reset to make the upstream
module choose the next server listen on 9901. I made this by setting the
request_terminate_timeout argument to 1s.



Send a put request, test.png is a file sized 90833 bytes(>64K)

$ curl -T test.png *http://127.0.0.1:8080/index.php
<http://127.0.0.1:8080/index.php>* -v
* About to connect() to 127.0.0.1 port 8080 (#0)
*   Trying 127.0.0.1...
* Adding handle: conn: 0x7fda7b803a00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7fda7b803a00) send_pipe: 1, recv_pipe: 0
* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
> PUT /index.php HTTP/1.1
> User-Agent: curl/7.30.0
> Host: 127.0.0.1:8080
> Accept: */*
> Content-Length: 90833
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 200 OK
* Server nginx/1.5.12 is not blacklisted
< Server: nginx/1.5.12
< Date: Tue, 17 Jun 2014 13:55:30 GMT
< Content-Type: text/html
< Transfer-Encoding: chunked
< Connection: keep-alive
< X-Powered-By: PHP/5.4.24
<
* Connection #0 to host 127.0.0.1 left intact
65536%


The response status is 200 OK, but only 65536 bytes(64k) received.
Is this a bug or have i made something wrong in the config file?
I’m really confusing and hope if someone could help me figure it out.

Many thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20140617/493dc66f/attachment.html>


More information about the nginx-devel mailing list