前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >专栏 >Nginx HTTP Post Method: 405 Method not allowed解决方法

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

作者头像
星哥玩云
发布2022-06-30 21:01:35
发布2022-06-30 21:01:35
4.7K0
举报
文章被收录于专栏:开源部署开源部署

最近维护一台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;

}

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档