您的位置:首页 > 运维架构 > Nginx

Nginx 1.15.5: 405 Not Allowed

2019-08-15 00:00 1171 查看

0x00 事件

在做一个业务跳转时,遇到这个错误 405 Not Allowed,找了挺多资料,多数解决方案是让在 nginx 配置文件中直接添加 error_page 405 =200 $uri; 参数,而经过吾试验,这个修改方案似乎在当前 nginx 版本中是无效的。

$ curl -d test=test http://xxx.com
<html>
<head><title>405 Not Allowed</title></head>
<body>
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.15.5</center>
</body>
</html>

最后使用了以下这个方案,成功解决了这个 405 的问题。

步骤

修改 nginx 配置文件
upstream web-test  {
    server xx.xx.xx.xx;
}

server {
    listen 80;
    server_name xxx.com;   
    ……
    location / {
        proxy_method GET;
        proxy_pass    http://web-test;
    } 
}

只需要在 location 中添加 proxy_method GET;,原理就是将请求都转换为 GET 方法,修改完成之后再重启 nginx 即可。

Linux公社的RSS地址:https://www.linuxidc.com/rssFeed.aspx

本文永久更新链接地址https://www.linuxidc.com/Linux/2019-08/160093.htm

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Nginx 405 Not Allowed