Nginx的405 not allowed错误解决

1.首先看到的页面是nginx返回的页面,得知错误要从nginx上来解决

返回页面:

<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.0.11</center>
</body>
</html>

 

 

2.上网查资料,原来因为这里请求的静态文件采用的是post方法,nginx是不允许post访问静态资源。题话外,试着post访问了下www.baidu.com发现页面也是报错

 

3.现贴出三种解决方式

1.将405错误指向成功(我采用的这种方法解决的问题)

静态server下的location加入error_page 405 =200 $uri;

location ~ ^/better/.*\.(htm|html|gif|jpg|jpeg|png|ico|rar|css|js|zip|txt|flv|swf|doc|ppt|xls|pdf|json|ico|htc)$ {
<span style="white-space:pre">	</span>root D:/code/BetterjrWeb;
<span style="white-space:pre">	</span>error_page 405 =200 $uri;
}

 

 

2.修改nginx下src/http/modules/ngx_http_static_module.c文件

if (r->method & NGX_HTTP_POST) {
     return NGX_HTTP_NOT_ALLOWED;
}

这一段注释掉,重新编译,不要make install编译生成的nginx文件复制到sbin下  重启nginx

 

3.修改错误界面指向(网上多流传这种方式,但是没有改变请求方法,所以行不通,所以采用以下方法)

upstream static_backend {
    server localhost:80;
}

server {
    listen 80;
    # ...
    error_page 405 =200 @405;
    location @405 {
        root /srv/http;
        proxy_method GET;
        proxy_pass http://static_backend;
    }
}


 

转载于:https://my.oschina.net/u/1587199/blog/805301

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值