Nginx配置:
server {
Listen 1985;
root /home/tianfeng/lab/php;
location / {
index index.php index.html index.htm;
}
location ~ \.php$ {
access_by_lua_file '/home/tianfeng/lab/lua/test.lua';
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /home/work/nginx/conf/fastcgi_params;
}
}
/home/tianfeng/lab/lua/test.lua文件内容:
ngx.say("test")
/home/tianfeng/lab/php/index.php文件内容:
发如下POST请求:
curl -d "k=v" "http://172.16.0.210:1985"
tcpdump结果如下:
20:58:51.602468 IP 172.16.0.210.50799 > 172.16.0.210.1985: Flags [S], seq 740686924, win 43690, options [mss 65495,sackOK,TS val 644353861 ecr 0,nop,wscale 7], length 0
..............E..<. @.@............o..,%.L........Y..........
&h.E........
20:58:51.602486 IP 172.16.0.210.1985 > 172.16.0.210.50799: Flags [S.], seq 921964885, ack 740686925, win 43690, options [mss 65495,sackOK,TS val 644353861 ecr 644353861,nop,wscale 7], length 0
..............E..<..@.@..............o6..U,%.M....Y..........
&h.E&h.E....
20:58:51.602501 IP 172.16.0.210.50799 > 172.16.0.210.1985: Flags [.], ack 1, win 342, options [nop,nop,TS val 644353861 ecr 644353861], length 0
..............E..4.
@.@............o..,%.M6..V...VY......
&h.E&h.E
20:58:51.602570 IP 172.16.0.210.50799 > 172.16.0.210.1985: Flags [P.], seq 1:154, ack 1, win 342, options [nop,nop,TS val 644353861 ecr 644353861], length 153
..............E.....@.@..Z.........o..,%.M6..V...VZ......
&h.E&h.EPOST / HTTP/1.1
User-Agent: curl/7.29.0
Host: 172.16.0.210:1985
Accept: */*
Content-Length: 3
Content-Type: application/x-www-form-urlencoded
k=v
20:58:51.602577 IP 172.16.0.210.1985 > 172.16.0.210.50799: Flags [.], ack 154, win 350, options [nop,nop,TS val 644353861 ecr 644353861], length 0
..............E..4..@.@..............o6..V,%.....^Y......
&h.E&h.E
20:58:51.602740 IP 172.16.0.210.1985 > 172.16.0.210.50799: Flags [P.], seq 1:183, ack 154, win 350, options [nop,nop,TS val 644353861 ecr 644353861], length 182
..............E.....@.@..5...........o6..V,%.....^Z......
&h.E&h.EHTTP/1.1 200 OK
Server: openresty
Date: Tue, 23 Jun 2015 12:58:51 GMT
Content-Type: application/octet-stream
Transfer-Encoding: chunked
Connection: keep-alive
5
test
0
20:58:51.602748 IP 172.16.0.210.50799 > 172.16.0.210.1985: Flags [.], ack 183, win 350, options [nop,nop,TS val 644353861 ecr 644353861], length 0
..............E..4..@.@............o..,%..6......^Y......
&h.E&h.E
20:58:51.602817 IP 172.16.0.210.1985 > 172.16.0.210.50799: Flags [P.], seq 183:498, ack 154, win 350, options [nop,nop,TS val 644353861 ecr 644353861], length 315
..............E..o..@.@..............o6...,%.....^[&.....
&h.E&h.EHTTP/1.1 400 Bad Request
Server: openresty
Date: Tue, 23 Jun 2015 12:58:51 GMT
Content-Type: text/html
Content-Length: 166
Connection: close
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>nginx</center>
</body>
</html>
20:58:51.602824 IP 172.16.0.210.50799 > 172.16.0.210.1985: Flags [.], ack 498, win 359, options [nop,nop,TS val 644353861 ecr 644353861], length 0
@.@............o..,%..6..G...gY......
&h.E&h.E
20:58:51.602834 IP 172.16.0.210.1985 > 172.16.0.210.50799: Flags [F.], seq 498, ack 154, win 350, options [nop,nop,TS val 644353861 ecr 644353861], length 0
..............E..4..@.@..............o6..G,%.....^Y......
&h.E&h.E
20:58:51.602930 IP 172.16.0.210.50799 > 172.16.0.210.1985: Flags [F.], seq 154, ack 499, win 359, options [nop,nop,TS val 644353861 ecr 644353861], length 0
..............E..4..@.@............o..,%..6..H...gY......
&h.E&h.E
20:58:51.602939 IP 172.16.0.210.1985 > 172.16.0.210.50799: Flags [.], ack 155, win 350, options [nop,nop,TS val 644353861 ecr 644353861], length 0
..............E..4..@.@..............o6..H,%.....^Y......
&h.E&h.E
如上面抓包结果所示,1个request居然有2个response, 第2个是400错误。
加上ngx.exit(ngx.HTTP_OK)结果也一样。
GET请求没有问题。
求春哥解惑。
nginx version: openresty/1.7.10.1