用于 POST 的 NGINX 代理通行证
我有两个上游 A 和 B 分别在端口 8301 和 8303 上运行。我的目的是将反向代理放在它们前面,将 A 上失败的请求传递给 B。
我像这样配置了 nginx
daemon off;
events {}
http {
upstream api {
server host.docker.internal:8301;
server host.docker.internal:8303 backup;
}
server {
listen 8300;
location / {
proxy_pass http://api;
proxy_redirect off;
proxy_intercept_errors on;
proxy_next_upstream error http_403;
proxy_next_upstream error http_502;
}
}
}
当我运行 curl localhost:8300/xyz
时,A 响应 403
然后 nginx 将请求传递给 B。但这不适用于 POST。 curl -X POST localhost:8300/xyz
返回 403,并且没有尝试上游 B。
如何配置 nginx 来代理传递所有请求方法?
I have two upstreams A and B running on ports 8301 and 8303 respectively. My intention is to put reverse proxy in front of them which passes request that failed on A to B.
I configured nginx like this
daemon off;
events {}
http {
upstream api {
server host.docker.internal:8301;
server host.docker.internal:8303 backup;
}
server {
listen 8300;
location / {
proxy_pass http://api;
proxy_redirect off;
proxy_intercept_errors on;
proxy_next_upstream error http_403;
proxy_next_upstream error http_502;
}
}
}
When I run curl localhost:8300/xyz
and A responds with 403
then nginx passes request to B. But this does not work with POST. curl -X POST localhost:8300/xyz
returns 403 and there is no attempt for upstream B.
How do I configure nginx to proxy pass all request methods?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用 proxy_next_upstream 并需要重试 POST、LOCK、PATCH 等请求时,您将需要这样配置 proxy_next_upsteam。
来自 Nginx 文档
When you utilise proxy_next_upstream and require request like POST, LOCK, PATCH to be retried you will need to configure your proxy_next_upsteam as such.
From the Nginx Docs