Proxy domain rewrite using proxy_cookie_domain

Maxim Dounin mdounin at
Sat Feb 13 01:54:02 UTC 2016


On Fri, Feb 12, 2016 at 02:22:20PM -0500, nitin wrote:

> I want to rewrite domains in the cookie when NGIX is acting as reverse
> proxy. I see that NGIX support this using proxy_cookie_domain module.
> But I am unable to find out where does it keep the original domain which is
> being replaced? In my opinion NGIX would need the original domain to find
> out where to send the cookie when it comes back to NIGX in next request. 
> Let's says NGIX domain is:
> backend server #1 sets cookie domain as: 
> backend server #2 sets cookie domain as: 
> Both these domains are replaced by NGIX to NGIX's domain so both cookies'
> domain is now
> when the request comes to NGIX, both these cookies will be sent by browser
> to NGIX, now how does NGIX decide which cookies to be sent to the backend
> server? it needs to keep the original domain mapping to find this how, does
> it keep somewhere? 

The domain is only present in Set-Cookie response headers, but it 
is not available in HTTP requests.  The client decides which 
cookies to send back to nginx in the Cookie request header, and 
nginx just passes the header with all cookies unmodified.

Maxim Dounin

More information about the nginx mailing list