我有下一个配置的nginx 1.2.7:
upstream backend_kes {
ip_hash;
server 127.0.0.1:9140 max_fails=1 fail_timeout=3s;
}
....
location = /file/add {
keepalive_timeout 0;
set $upload_progress_fallback_code 360;
set $upload_progress_memcached_servers "127.0.0.2:11211";
set $upload_progress_memcached_namespace setup-team.net;
set $upload_progress_memcached_compress_threshold 10000;
error_page 360 = @root2;
perl My::handle;
}
location @root2 {
proxy_pass http://backend_kes;
}
此处理程序处理文件上载。一切都适用于大文件,但不保存小文件。 tcpdump显示下一个:
08:58:02.470116 IP 127.0.0.1.48396 > 127.0.0.1.9140: Flags [S], seq 1692815180, win 32792, options [mss 16396,sackOK,TS val 3699243831 ecr 0,nop,wscale 7], length 0
0x0000: 4500 003c b47b 4000 4006 883e 7f00 0001 E..<.{@.@..>....
0x0010: 7f00 0001 bd0c 23b4 64e6 4f4c 0000 0000 ......#.d.OL....
0x0020: a002 8018 fe30 0000 0204 400c 0402 080a .....0....@.....
0x0030: dc7d fb37 0000 0000 0103 0307 .}.7........
08:58:02.470146 IP 127.0.0.1.9140 > 127.0.0.1.48396: Flags [S.], seq 2061404772, ack 1692815181, win 32768, options [mss 16396,sackOK,TS val 3699243831 ecr 3699243831,nop,wscale 7], length 0
0x0000: 4500 003c 0000 4000 4006 3cba 7f00 0001 E..<..@.@.<.....
0x0010: 7f00 0001 23b4 bd0c 7ade 8a64 64e6 4f4d ....#...z..dd.OM
0x0020: a012 8000 fe30 0000 0204 400c 0402 080a .....0....@.....
0x0030: dc7d fb37 dc7d fb37 0103 0307 .}.7.}.7....
08:58:02.470165 IP 127.0.0.1.48396 > 127.0.0.1.9140: Flags [.], ack 1, win 257, options [nop,nop,TS val 3699243831 ecr 3699243831], length 0
0x0000: 4500 0034 b47c 4000 4006 8845 7f00 0001 E..4.|@.@..E....
0x0010: 7f00 0001 bd0c 23b4 64e6 4f4d 7ade 8a65 ......#.d.OMz..e
0x0020: 8010 0101 fe28 0000 0101 080a dc7d fb37 .....(.......}.7
0x0030: dc7d fb37 .}.7
08:58:02.471383 IP 127.0.0.1.48396 > 127.0.0.1.9140: Flags [F.], seq 1, ack 1, win 257, options [nop,nop,TS val 3699243832 ecr 3699243831], length 0
0x0000: 4500 0034 b47d 4000 4006 8844 7f00 0001 E..4.}@.@..D....
0x0010: 7f00 0001 bd0c 23b4 64e6 4f4d 7ade 8a65 ......#.d.OMz..e
0x0020: 8011 0101 fe28 0000 0101 080a dc7d fb38 .....(.......}.8
0x0030: dc7d fb37 .}.7
08:58:02.471603 IP 127.0.0.1.9140 > 127.0.0.1.48396: Flags [F.], seq 1, ack 2, win 256, options [nop,nop,TS val 3699243832 ecr 3699243832], length 0
0x0000: 4500 0034 715d 4000 4006 cb64 7f00 0001 E..4q]@.@..d....
0x0010: 7f00 0001 23b4 bd0c 7ade 8a65 64e6 4f4e ....#...z..ed.ON
0x0020: 8011 0100 fe28 0000 0101 080a dc7d fb38 .....(.......}.8
0x0030: dc7d fb38 .}.8
08:58:02.471641 IP 127.0.0.1.48396 > 127.0.0.1.9140: Flags [.], ack 2, win 257, options [nop,nop,TS val 3699243832 ecr 3699243832], length 0
0x0000: 4500 0034 b47e 4000 4006 8843 7f00 0001 E..4.~@.@..C....
0x0010: 7f00 0001 bd0c 23b4 64e6 4f4e 7ade 8a66 ......#.d.ONz..f
0x0020: 8010 0101 fe28 0000 0101 080a dc7d fb38 .....(.......}.8
0x0030: dc7d fb38 .}.8
正如您所看到的,每个数据包都有length 0
。对于大文件&gt; 30kb(我不检查1500字节,3000字节)我看到数据包长度。
这是否是nginx的错误,如果它适合内存(或者可能是一个网络数据包<1500b),它不会发送POST请求主体的内容?
按照设计,我总是从My :: handler
返回后备代码答案 0 :(得分:0)
处理程序逻辑中存在错误。如果没有正文,我们应该发送204状态代码而不是200.
如果我们为空体nginx发送200只是关闭连接而浏览器没有显示任何内容。
IMHO。这很令人困惑,在浏览器中看不到任何东西似乎很难看。但在nginx日志中状态良好:
2016/06/08 22:38:49 [debug] 21440#0: *13 HTTP/1.1 200 OK
Server: nginx/1.2.7
Date: Wed, 08 Jun 2016 19:38:49 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close