最近维护一台RedHat 5.4 X64系统,环境是Nginx,跑着一个论坛,需要向HTML页面提交POST数据,结果都被拦截下来了,显示错误:“nginx 405 Not Allowed”,是乎没有很好的解决办法,唯一能做的就是重新编译Nginx源码和编辑conf文件。
相关阅读:
CentOS 6.2实战部署Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm
使用Nginx搭建WEB服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm
搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm
CentOS 6.3下Nginx性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm
CentOS 6.3下配置Nginx加载ngx_pagespeed模块 http://www.linuxidc.com/Linux/2013-09/89657.htm
CentOS 6.4安装配置Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm
Nginx搭建视频点播服务器(仿真专业流媒体软件) http://www.linuxidc.com/Linux/2012-08/69151.htm
需要修改Nginx中的C源码文件位于 /nginx源码目录/src/http/modules/ngx_http_static_module.c ,找到如下代码:
if (r->method & NGX_HTTP_POST) {return NGX_HTTP_NOT_ALLOWED;}注释掉如下:
/*if (r->method & NGX_HTTP_POST) {return NGX_HTTP_NOT_ALLOWED;}*/然后再重新编译 make
复制/nginx源码目录/ objs 目录下的 nginx至安装的Nginx目录下,重启Nginx生效。
对于Nginx,可以修改nginc.conf配置文件,改变“405错误”为“200 ok”,并配置location来解决,方法如下:
server { listen 80; server_name www.kiccleaf.com; index index.html index.htm index.php; root /data/kiccleaf; if ($host != 'www.kiccleaf.com' ) {rewrite ^/(.*)$ http://www.kiccleaf.com/$1 permanent;}location ~ .*\.(php|php5)?${fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include fcgi.conf;}#添加以下405代码error_page 405 =200 @405; location @405 { root /data/kiccleaf; } } 也可以简单的编写成
server { listen 80; server_name www.kiccleaf.com; index index.html index.htm index.php; root /data/kiccleaf; if ($host != 'www.kiccleaf.com' ) {rewrite ^/(.*)$ http://www.kiccleaf.com/$1 permanent;}location ~ .*\.(php|php5)?${fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php;include fcgi.conf;}#添加以下405代码error_page 405 =200 $uri; } Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里
