Nginx 1.15.5: 405 Not Allowed


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 即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM