0x00 事件
在做一個(gè)業(yè)務(wù)跳轉(zhuǎn)時(shí),遇到這個(gè)錯(cuò)誤 405 Not Allowed,找了挺多資料,多數(shù)解決方案是讓在 nginx 配置文件中直接添加 error_page 405 =200 $uri; 參數(shù),而經(jīng)過吾試驗(yàn),這個(gè)修改方案似乎在當(dāng)前 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>
最后使用了以下這個(gè)方案,成功解決了這個(gè) 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;,原理就是將請(qǐng)求都轉(zhuǎn)換為 GET 方法,修改完成之后再重啟 nginx 即可。