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