# Modifying or adding cookies via nginx.conf

**URL:** <https://www.ruby-forum.com/t/modifying-or-adding-cookies-via-nginx-conf/130942>\
**Category:** NGINX\
**Created:** [March 4, 2008, 5:50pm UTC](https://www.ruby-forum.com/t/modifying-or-adding-cookies-via-nginx-conf/130942 "2008-03-04T17:50:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Laurent\_Thevenet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f14d63/32.png) [@Laurent\_Thevenet](https://www.ruby-forum.com/u/Laurent_Thevenet)\
**Post date:** [March 4, 2008, 5:50pm UTC](https://www.ruby-forum.com/t/modifying-or-adding-cookies-via-nginx-conf/130942/1 "2008-03-04T17:50:35Z")

</div>

Hi,

I’m dealing with the issue of modifying or adding a cookie on the fly  
via nginx.conf

I look through all the doc and did not find anything except about  
identification ([http://wiki.codemongers.com/NginxHttpUserIdModule](http://wiki.codemongers.com/NginxHttpUserIdModule)) and  
from an external module i forgot about the name (allowing to access  
cookies individually but not to set them for the moment).

So, as i want a cookie value to depend on the URL, i’m looking at all  
the options and i just want to know if it’s possible and where to look  
for in that case.

Thx guys.

---

<div class="post-metadata">

**Author:** ![Laurent\_Thevenet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f14d63/32.png) [@Laurent\_Thevenet](https://www.ruby-forum.com/u/Laurent_Thevenet)\
**Post date:** [March 4, 2008, 7:30pm UTC](https://www.ruby-forum.com/t/modifying-or-adding-cookies-via-nginx-conf/130942/2 "2008-03-04T19:30:30Z")

</div>

Laurent Thevenet ha scritto:

> Hi,
> 
> I’m dealing with the issue of modifying or adding a cookie on the fly  
> via nginx.conf
> 
> I look through all the doc and did not find anything except about  
> identification ([http://wiki.codemongers.com/NginxHttpUserIdModule](http://wiki.codemongers.com/NginxHttpUserIdModule)) and  
> from an external module i forgot about the name (allowing to access  
> cookies individually but not to set them for the moment).

Do you mean this:  
[http://hg.mperillo.ath.cx/nginx/mod\_parsed\_vars/](http://hg.mperillo.ath.cx/nginx/mod_parsed_vars/)  
?

It’s a module I have written some time ago.

> So, as i want a cookie value to depend on the URL, i’m looking at all  
> the options and i just want to know if it’s possible and where to look  
> for in that case.
> 
> Thx guys.

What do you want to do, in detail?

Regards Manlio P.

---

<div class="post-metadata">

**Author:** ![Laurent\_Thevenet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f14d63/32.png) [@Laurent\_Thevenet](https://www.ruby-forum.com/u/Laurent_Thevenet)\
**Post date:** [March 4, 2008, 11:00pm UTC](https://www.ruby-forum.com/t/modifying-or-adding-cookies-via-nginx-conf/130942/3 "2008-03-04T23:00:35Z")

</div>

On Wed, Mar 5, 2008 at 2:19 AM, Manlio P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Thx guys.
> 
> What do you want to do, in detail?

I wanted to set up a language cookie depending on the url as googlebot  
is indexing all our content in english when the website is available  
both in french and in english. It’s more a conception issue and i  
wanted a temporary but immediate solution, as nginx is in front of a  
mongrel cluster in fact and setting up a cookie was one of them.

And yes it was your mod (parsed vars) that i saw 😉

---

<div class="post-metadata">

**Author:** ![Laurent\_Thevenet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f14d63/32.png) [@Laurent\_Thevenet](https://www.ruby-forum.com/u/Laurent_Thevenet)\
**Post date:** [March 6, 2008, 1:12pm UTC](https://www.ruby-forum.com/t/modifying-or-adding-cookies-via-nginx-conf/130942/4 "2008-03-06T13:12:05Z")

</div>

Laurent Thevenet ha scritto:

> On Wed, Mar 5, 2008 at 2:19 AM, Manlio P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:  
> […]
> 
> > What do you want to do, in detail?
> 
> I wanted to set up a language cookie depending on the url as googlebot  
> is indexing all our content in english when the website is available  
> both in french and in english.

How is the language selected?  
It’s strange if a cookie will solve the problem.

> It’s more a conception issue and i  
> wanted a temporary but immediate solution, as nginx is in front of a  
> mongrel cluster in fact and setting up a cookie was one of them.
> 
> And yes it was your mod (parsed vars) that i saw 😉

You can try with:  
add\_header Cookie “lang=$request\_url”

If you need more control, then you have to write a custom extension.

Manlio P.

---

<div class="post-metadata">

**Author:** ![Laurent\_Thevenet](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f14d63/32.png) [@Laurent\_Thevenet](https://www.ruby-forum.com/u/Laurent_Thevenet)\
**Post date:** [March 7, 2008, 8:53am UTC](https://www.ruby-forum.com/t/modifying-or-adding-cookies-via-nginx-conf/130942/5 "2008-03-07T08:53:57Z")

</div>

On Thu, Mar 6, 2008 at 7:56 PM, Manlio P.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > both in french and in english.
> 
> How is the language selected?  
> It’s strange if a cookie will solve the problem.

Initial language selection (as it can be change manually after) is  
made based on your IP but i’m not in charge of that so i cannot tell  
you exactly how it’s working. I simply know a cookie is holding the  
language selection after that, i just wanted to force it or to give  
the web developer an indication about the language depending on the  
url (if subdomain is [fr.fonzz.com](http://fr.fonzz.com) for example).

The issue was concerning the search engine bots that would have  
consider our pages to be duplicated as bots are not handling cookies  
and google bot is for example always considered speaking english.

But we have dealt with the issue differently by doing all these things  
in the web code so i’m not in charge of that anymore but adding  
headers in nginx.conf was just one of the solution

> add\_header Cookie “lang=$request\_url”

We hae done that, it was working fine but we change our plans finally  
as it was only an immeida
