我有兩個上游 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 回應時,403nginx 將請求傳遞給 B。但這不適用于 POST。curl -X POST localhost:8300/xyz回傳 403,上游 B 沒有嘗試。
如何配置 nginx 以代理傳遞所有請求方法?
uj5u.com熱心網友回復:
當您使用 proxy_next_upstream 并要求重試 POST、LOCK、PATCH 等請求時,您需要像這樣配置您的 proxy_next_upsteam。
proxy_next_upstream error http_403 non_idempotent;
proxy_next_upstream error http_502 non_idempotent;
來自Nginx 檔案
non_idempotent
normally, requests with a non-idempotent method (POST, LOCK, PATCH) are not passed to the next server if a request has been sent to an upstream server (1.9.13); enabling this option explicitly allows retrying such requests;
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/432649.html
