你好,游客 登录 注册 搜索
背景:
阅读新闻

Nginx HTTP Post Method: 405 Method not allowed解决方法

[日期:2014-04-13] 来源:Linux社区  作者:Linux [字体:大 中 小]

最近维护一台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 的下载地址:请点这里

linux
相关资讯       Nginx 405 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款