# Cookie not created until refresh?

**URL:** <https://www.ruby-forum.com/t/cookie-not-created-until-refresh/224884>\
**Category:** NGINX\
**Created:** [November 29, 2012, 8:15pm UTC](https://www.ruby-forum.com/t/cookie-not-created-until-refresh/224884 "2012-11-29T20:15:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [November 29, 2012, 8:15pm UTC](https://www.ruby-forum.com/t/cookie-not-created-until-refresh/224884/1 "2012-11-29T20:15:30Z")

</div>

I have the following nginx conf file (shortened for the purose of this  
question) that is creating a cookie:

```
map $http_referer $setCookie {
        default "";
        ~*somewebsite\.com

```

“referrer=bl;[Domain=.mysite.com](http://Domain=.mysite.com);Max-Age=31536000”;  
}

```
server{

    listen 80;

    server_name mysite.com www.mysite.com dev.mysite.com;

    root /var/www/mysite.com;

    access_log /var/log/nginx/mysite.com.log spiegle;

    add_header Set-Cookie $setCookie;

    location /{
                #add_header Set-Cookie $setCookie;
    }
}

```

The issue is that if I click on a link on `somewebsite.com` it navigates  
to  
mysite, but does not create the cookie. If I then refresh the page it  
will  
create the cookie. Why do I have to refresh to have the cookie created  
and  
how can I get around this?

Posted at Nginx Forum:

> **[Cookie not created until refresh?](https://forum.nginx.org/read.php?2,233395,233395#msg-233395)**
>
> I have the following nginx conf file (shortened for the purose of this question) that is creating a cookie: map $http\_referer $setCookie { default ""; ~\*somewebsite\\.com "referrer=bl;Domain=.mysite.com;Max-Age=31536000

---

<div class="post-metadata">

**Author:** ![Broham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e56c9b/32.png) [@Broham](https://www.ruby-forum.com/u/Broham)\
**Post date:** [November 30, 2012, 5:24am UTC](https://www.ruby-forum.com/t/cookie-not-created-until-refresh/224884/2 "2012-11-30T05:24:45Z")

</div>

On 11/29/2012 11:14 PM, Broham wrote:

- ~\*somewebsite.com “referrer=bl;[Domain=.mysite.com](http://Domain=.mysite.com);Max-Age=31536000”;

- .somewebsite.com “referrer=bl;[Domain=.mysite.com](http://Domain=.mysite.com);Max-Age=31536000”;
