Intercepting backend 301/302 redirects (proxy_pass) and rewriting to another location block possible?

前端 未结 4 1064
悲&欢浪女
悲&欢浪女 2020-12-01 14:11

We have a couple of backends sitting behind our nginx front ends.

Is it possible to intercept 301 / 302 redirects sent by these backends and have nginx handle them?<

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 14:45

    You could use proxy_redirect directive:

    http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_redirect

    Nginx will still return 301/302 to the client but proxy_redirect will modify Location header and the client should make a new request to the URL given in the Location header.

    Something like this should make the subsequent request back to nginx:

    proxy_redirect http://upstream:port/ http://$http_host/;

提交回复
热议问题