【发布时间】:2019-05-20 02:17:45
【问题描述】:
当我尝试通过 Nginx 反向代理向我的 Tomcat 服务器请求时收到 405 响应。
如果我直接向 tomcat 服务器请求,它可以从 Chrome 或 Firefox 成功运行。但是,如果我向 Nginx 代理请求,我会从 Chrome 获得 405,但可以在 Firefox 中使用。
我一直在我的 nginx.conf 中使用不同的配置进行测试 位置/foo/ { ... }
我试过了:
error_page 405 =200 $uri;
还有
add_header "Allow" "GET, POST, HEAD, PUT, DELETE" always;
add_header "Access-Control-Allow-Methods" "GET, POST, PUT, DELETE, OPTIONS" always;`
location / {
dav_methods PUT DELETE;
proxy_pass http://csprocure;
}
我用于重定向的 nginx.conf 如下:
upstream serverS {
server xxx.xxx.xxx.xxx:yyyy;
}
server {
listen 80;
server_name $hostname;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
error_log /dev/stdout info;
access_log /dev/stdout;
location /foo/ {
proxy_pass http://serverS;
proxy_redirect http://xxx.xxx.xxx.xxx/ http://xxx.xxx.xxx.xxx:yyyy/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto: https;
}
我可以在我的配置中添加什么来避免 Chrome 中的 405?
【问题讨论】:
-
请将您的答案作为答案发布,而不是在问题中。
-
只接受一个答案,而不是改变你的标题说它已经解决了。
-
@JoshLee 添加为答案,谢谢
-
@csmckelvey 我刚刚添加了一个答案,我已经接受了。谢谢。
标签: google-chrome tomcat put nginx-reverse-proxy http-status-code-405