set cookie if not already set

amodpandey nginx-forum at
Thu Dec 13 18:29:07 UTC 2012

I figured out a simple solution so thought to share it ( to get feedback or
may be to help ). In an earlier discussion I got to know about map and why
one should avoid to use if an try to use map.

http {

    map $cookie_abt $abt {
        default "abt=a;Path=/";
        ~.+$ "";

    server {
        listen 8081;

        location / {
            add_header Set-Cookie $abt;


the map returns "" ( empty ) if cookie is already else the cookie value (
abt=a;Path=/" ). The good news is add_header Set-Cookie "" does not set any
cookie and we are good to go :)


Any feedback?

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

More information about the nginx mailing list