最近维护一台RedHat 5.4 X64系统,环境是Nginx,跑着一个论坛,需要向HTML页面提交POST数据,结果都被拦截下来了,显示错误:“nginx 405 Not Allowed”,是乎没有很好的解决办法,唯一能做的就是重新编译Nginx源码和编辑conf文件。
需要修改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;
}
Leave a Comment