nginx 设置允许post请求访问静态文件
的有关信息介绍如下:
nginx不允许向静态文件提交post方式的请求,否则会返回“HTTP/1.1 405 Method not allowed”错误,那么如何设置允许访问呢
比如 post请求静态html的
会返回nginx的405错误
那么如何设置有三种方法,1种
重定向405错误码到200
在nginx server{}里面添加以下内容,root为站点的根目录
location ~ (.*\.json) { root /data/web/www; error_page 405 =200 $1; }
nginx reload下即可
2种,
转换静态文件接收的POST请求到GET方法去
upstream static_backend { server localhost:80;}server { listen 80; ... error_page 405 =200 @405; location @405 { root /data/web/coolnull.com/www; proxy_method GET; proxy_pass http://static_backend; }}
3种
源码文件位于/nginx源码目录/src/http/modules/ngx_http_static_module.c,找到如下代码:
if (r->method & NGX_HTTP_POST) { return NGX_HTTP_NOT_ALLOWED;}
整段注释掉,然后重新编译 make,不需要make install,把编译生成的nginx文件复制到sbin下的nginx文件,重启nginx即可。



