3

I want to add remote ip as a Cookie in Nginx, so that it can be passed on to AWS Load Balancer for Load balancer stickiness.

location / {
     proxy_set_header Cookie "$http_cookie; ip=$remote_addr";
     proxy_pass http://app_upstream;
}

I am using these to set the cookie, but AWS ELB is not accepting this as stickiness. Since this server is used as an iframe, I can't use ELB generated cookie for load balancing in case of Safari/iOs which block 3rd party cookies by default.

I am open to ditching nginx and writing a custom reverse proxy as well.

Ashok Kumar Sahoo
  • 133
  • 1
  • 1
  • 3

1 Answers1

5

The variable $http_ is about the http header. So if you have $http_host, it's grabbing the host from the header. If you say $http_cookie, you're getting the entire cookie.

The variable $cookie_ is about a specific cookie. So if you have $cookie_foo, then you get the value of the cookie named foo, which may be bar.

Cookies are passed automatically, you don't need to do anything about it unless it has a different domain or path. If you're trying to add a specific cookie, it would be:

add_header Set-Cookie foo=bar;
Grumpy
  • 2,939
  • 17
  • 23