Nginx overwrite existing cookies with add_header

c0nw0nk nginx-forum at
Thu Aug 25 19:24:41 UTC 2016

So i am using Nginx to set a header now my PHP app sets this header too but
it sets the cookie with a domain of ""

Nginx keeps setting it as "" i need to overwrite the
cookie not create a new one.

I have tried the following :

add_header Set-Cookie "logged_in=1;Path=/;Max-Age=315360000";

That created a new cookie with a domain of "" instead of
overwriting the previous cookie with a domain of ""

This is also has the same outcome as above.

add_header Set-Cookie "logged_in=1;Domain=$host;Path=/;Max-Age=315360000";

Does anyone know how you can overwrite the existing cookie without having to
specify the add_header like this.

add_header Set-Cookie
The reason i can't use this method is because on the Nginx server there are
multiple hosts, it is why i try to use $host but would need to remove the
www at the start for it to work.

Posted at Nginx Forum:,269189,269189#msg-269189

More information about the nginx mailing list