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