Apache、IIS、Nginx等绝大多数web服务器,都不允许静态文件响应POST请求,否则会返回“HTTP/1.1 405 Method not allowed”错误。
[root@localhost ~]# curl -d 1=1 http://192.168.2.156/index.txt
<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.2.3</center>
</body>
</html>
error_page 405 =200 @405;
location @405
{
root /opt/htdocs;
}
改变405错误,返回200,用location解决。
error_page 405 =200 @405;
location @405 {
proxy_method GET;
proxy_pass http://$host;
}
我这边也是改变405错误,返回200,并改为get请求,重新访问,在访问日志上会有两条访问记录。
192.168.2.156 - - [08/Nov/2012:22:12:17 +0800] "POST /index.txt HTTP/1.1" 200 4 "-" "curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2"
192.168.2.156 - - [08/Nov/2012:22:12:17 +0800] "GET /index.txt HTTP/1.0" 200 4 "-" "curl/7.19.7 (i386-redhat-linux-gnu) libcurl/7.19.7 NSS/3.13.1.0 zlib/1.2.3 libidn/1.18 libssh2/1.2.2"