Altering HTTP Headers

Nick Pearson nick.pearson at
Fri Aug 14 03:25:45 MSD 2009

I've not tried this, but I'm guessing it might work.  This assumes
your cookie's name is "something" and has a value of at least one
character in length (hence the ".+" regex).

location  /  {
  if ($cookie_something ~* ".+") {
    add_header  Cookie  "$cookie_something  your_suffix_here";

If you need the suffix to come just after the cookie's original value
(with no spaces in between) you may be able to use the variable format
${cookie_comething} instead of just $cookie_something.  This is
another thing I haven't tried myself, but I wouldn't be surprised if
it worked.

Hope that helps, or at least gets you pointed in the right direction.


On Thu, Aug 13, 2009 at 6:02 PM, Ian Shafer<ian at> wrote:
> Hello All,
> I've migrated from Apache 2 to nginx. Everything is great, except I cannot
> figure out how to alter a n HTTP header. Here's what's happening. I'm using
> nginx as a reverse proxy. The upstream server sets a cookie using the
> Set-Cookie HTTP header. I want to append something to the end of that header
> before it gets to the client.
> So, upstream server sends
> Set-Cookie: Name=Value
> I want it to look like this
> Set-Cookie: Name=ValueAppendedContent
> How can I do this in nginx? In Apache, here's what I did:
> Header edit Set-Cookie $ 'AppendedContent'
> Maybe I should mention that I'm doing this because I want to specify the
> cookie domain. (I would do this in my upstream server, but it is
> difficult/not possible.)
> Thanks for any tips!
> Ian

More information about the nginx mailing list