<div dir="ltr"><span style="font-size:13px;font-family:Arial">Hello all,</span><br>
<span style="font-size:13px;font-family:Arial"></span><br>
<span style="font-size:13px;font-family:Arial">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.</span><br>
<span style="font-size:13px;font-family:Arial"></span><br>
<span style="font-size:13px;font-family:Arial">My nginx version is 1.5.12, and the problem remains when i switched to the newest 1.7.2.</span><br>
<span style="font-size:13px;font-family:Arial"></span><br>
<span style="font-size:13px;font-family:Arial"></span><br>
<span style="font-size:13px;font-family:Arial">Here is my nginx.conf file,</span><br>
<span style="font-size:13px;font-family:Arial"></span><br>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px"><span style="font-size:13px;font-family:Arial"> upstream </span><span style="font-size:13px;font-family:Arial;color:rgb(4,46,238)"><u><a href="http://api.php.com">api.php.com</a></u></span><span style="font-size:13px;font-family:Arial"> {<br>
</span><span style="font-size:13px;font-family:Arial"> server <a href="http://127.0.0.1:9902">127.0.0.1:9902</a> max_fails=3 fail_timeout=30s;<br></span><span style="font-size:13px;font-family:Arial"> server <a href="http://127.0.0.1:9901">127.0.0.1:9901</a> max_fails=3 fail_timeout=30s;<br>
</span><span style="font-size:13px;font-family:Arial"> }</span><br><span style="font-size:13px;font-family:Arial"> server {<br></span><span style="font-size:13px;font-family:Arial"> listen 8080;<br></span><span style="font-size:13px;font-family:Arial"> server_name localhost;</span><br>
<span style="font-size:13px;font-family:Arial"> location ~ \.php$ {<br></span><span style="font-size:13px;font-family:Arial"> root html;<br></span><span style="font-size:13px;font-family:Arial"> fastcgi_pass </span><span style="font-size:13px;font-family:Arial;color:rgb(4,46,238)"><u><a href="http://api.php.com">api.php.com</a></u></span><span style="font-size:13px;font-family:Arial">;<br>
</span><span style="font-size:13px;font-family:Arial"> fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name;<br></span><span style="font-size:13px;font-family:Arial"> fastcgi_index index.php;<br>
</span><span style="font-size:13px;font-family:Arial"> include fastcgi_params;<br></span><span style="font-size:13px;font-family:Arial"> }</span></blockquote>
<span style="font-size:13px;font-family:Arial"></span>
<span style="font-size:13px;font-family:Arial"></span><br>
<span style="font-size:13px;font-family:Arial"></span><br>
<span style="font-size:13px;font-family:Arial">And the index.php file,</span><br>
<span style="font-size:13px;font-family:Arial"></span><br>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px"><span style="font-size:13px;font-family:Arial"><?php<br></span><span style="font-size:13px;font-family:Arial">/* simplify get the request body and print its length. */<br>
</span><span style="font-size:13px;font-family:Arial">$raw_post_data = file_get_contents('php://input', 'r');<br></span><span style="font-size:13px;font-family:Arial">print(strlen($raw_post_data));<br></span><span style="font-size:13px;font-family:Arial">sleep(3); /* waiting for the server to be reset after 1 second */<br>
</span><span style="font-size:13px;font-family:Arial">?></span></blockquote>
<span style="font-size:13px;font-family:Arial"></span><br>
<span style="font-size:13px;font-family:Arial">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.</span><br>
<span style="font-size:13px;font-family:Arial"></span><br>
<span style="font-size:13px;font-family:Arial"></span><br>
<span style="font-size:13px;font-family:Arial"></span><br>
<span style="font-size:13px;font-family:Arial">Send a put request, test.png is a file sized 90833 bytes(>64K)</span><br>
<span style="font-size:13px;font-family:Arial"></span><br>
<blockquote style="margin:0 0 0 40px;border:none;padding:0px"><span style="font-size:13px;font-family:Arial">$ curl -T test.png </span><span style="font-size:13px;font-family:Arial;color:rgb(4,46,238)"><u><a href="http://127.0.0.1:8080/index.php">http://127.0.0.1:8080/index.php</a></u></span><span style="font-size:13px;font-family:Arial"> -v<br>
</span><span style="font-size:13px;font-family:Arial">* About to connect() to 127.0.0.1 port 8080 (#0)<br></span><span style="font-size:13px;font-family:Arial">* Trying 127.0.0.1...<br></span><span style="font-size:13px;font-family:Arial">* Adding handle: conn: 0x7fda7b803a00<br>
</span><span style="font-size:13px;font-family:Arial">* Adding handle: send: 0<br></span><span style="font-size:13px;font-family:Arial">* Adding handle: recv: 0<br></span><span style="font-size:13px;font-family:Arial">* Curl_addHandleToPipeline: length: 1<br>
</span><span style="font-size:13px;font-family:Arial">* - Conn 0 (0x7fda7b803a00) send_pipe: 1, recv_pipe: 0<br></span><span style="font-size:13px;font-family:Arial">* Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)<br>
</span><span style="font-size:13px;font-family:Arial">> PUT /index.php HTTP/1.1<br></span><span style="font-size:13px;font-family:Arial">> User-Agent: curl/7.30.0<br></span><span style="font-size:13px;font-family:Arial">> Host: <a href="http://127.0.0.1:8080">127.0.0.1:8080</a><br>
</span><span style="font-size:13px;font-family:Arial">> Accept: */*<br></span><span style="font-size:13px;font-family:Arial">> Content-Length: 90833<br></span><span style="font-size:13px;font-family:Arial">> Expect: 100-continue<br>
</span><span style="font-size:13px;font-family:Arial">><br></span><span style="font-size:13px;font-family:Arial">< HTTP/1.1 100 Continue<br></span><span style="font-size:13px;font-family:Arial">* We are completely uploaded and fine<br>
</span><span style="font-size:13px;font-family:Arial">< HTTP/1.1 200 OK<br></span><span style="font-size:13px;font-family:Arial">* Server nginx/1.5.12 is not blacklisted<br></span><span style="font-size:13px;font-family:Arial">< Server: nginx/1.5.12<br>
</span><span style="font-size:13px;font-family:Arial">< Date: Tue, 17 Jun 2014 13:55:30 GMT<br></span><span style="font-size:13px;font-family:Arial">< Content-Type: text/html<br></span><span style="font-size:13px;font-family:Arial">< Transfer-Encoding: chunked<br>
</span><span style="font-size:13px;font-family:Arial">< Connection: keep-alive<br></span><span style="font-size:13px;font-family:Arial">< X-Powered-By: PHP/5.4.24<br></span><span style="font-size:13px;font-family:Arial"><<br>
</span><span style="font-size:13px;font-family:Arial">* Connection #0 to host 127.0.0.1 left intact<br></span><span style="font-size:13px;font-family:Arial">65536% </span></blockquote>
<span style="font-size:13px;font-family:Arial"></span><br>
<span style="font-size:13px;font-family:Arial">The response status is 200 OK, but only 65536 bytes(64k) received. </span><br>
<span style="font-size:13px;font-family:Arial">Is this a bug or have i made something wrong in the config file? </span><br>
<span style="font-size:13px;font-family:Arial">I’m really confusing and hope if someone could help me figure it out. </span><br><div> </div>Many thanks!
<span style="font-size:13px;font-family:Arial"></span><br>
<span style="font-size:13px;font-family:Arial"></span><br></div>