Problem using `proxy_redirect` to rewrite the same Location 2-or-more times?

Alec Muffett alec.muffett at
Fri Dec 8 20:48:55 UTC 2017

Hi! I am using Nginx 1.12.2 in a large and complex reverse-proxy
configuration, with lots of content-rewriting (subs_filter, lua, ...).


- the client connects to my proxy
- my proxy forwards the request to the origin
- the origin responds with a 302:

 "Location:" ...or
 "Location:" ...or

...and I have the following dynamic rewriting that I want to perform:

* ->
* ->
* ->
* ...more?

So I have the following three (or more) rules:

 http {
 # ...etc
 proxy_redirect ~*^(.*?)\\b{foo\\.com}\\b(.*)$ $$2;
 proxy_redirect ~*^(.*?)\\b{bar\\.com}\\b(.*)$ $$2;
 proxy_redirect ~*^(.*?)\\b{baz\\.com}\\b(.*)$ $$2;
 # ...more?

...and these work well most of the time.

However: these do not function as-desired when the origin produces a 302
which mentions two or more *different* rewritable site names:

 "Location:" <-- INPUT

...which I *want* to be rewritten as:

 "Location:" <-- WANTED

...but instead I get:

 "Location:" <-- ACTUAL

i.e. the location is converted from `` to ``, but no further
processing happens to convert `` in this example.

The issue seems to be that `proxy_redirect` stops after executing the first
rule that succeeds?

Is this intended behaviour, please?  And is there a way to achieve what I
want, e.g. via options-flags or Lua? I am making heavy use of subs_filter,
proxy_cookie_domain, etc.

I've put one of my Nginx configuration files at if
you'd like to see the issue in context.


    - alec

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the nginx mailing list