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

Francis Daly francis at daoine.org
Mon Dec 18 22:26:39 UTC 2017


On Fri, Dec 08, 2017 at 08:48:55PM +0000, Alec Muffett wrote:

Hi there,

I have not tested this, but it looks like you might already have the
answer...

> - the origin responds with a 302:
> 
>  "Location: http://www.foo.com/" ...or
>  "Location: http://www.bar.com/" ...or
>  "Location: http://www.baz.com/"
> 
> ...and I have the following dynamic rewriting that I want to perform:
> 
> * foo.com -> ding.org
> * bar.com -> dong.org
> * baz.com -> dell.org
> * ...more?

> 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 do not know if that stop-on-first-match is the intended behaviour. (But
I suspect that proxy_redirect expects to be called in a much simpler
scenario than yours.)

You do currently have a header_filter_by_lua_block{} section, where you
appear to rewrite three specific content-security-related headers based
on multiple regex matches.

Could you not do exactly the same with the "Location" header, since it
is just another header from upstream that will be sent to the client?

It seems so obvious that I guess you must have tried it; but you didn't
explicitly say that you did, so maybe it is worth a shot.

Cheers,

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list