We are working with a piece of hardware(chromecast) that seems to be stripping out cookies, but will happily pass along a custom header (which we signal is acceptable from the back end) one workaround we came up to stuff the cookie data into said custom header and put it back into the cookie header on the proxy. This allows most clients (which respect normal CORS signaling) and the backend to remain unchanged. In my Nginx config I currently have a map defined like:

map cookie $cookie {
    default   $http_cookie;
    ""        $http_my_token;

which I'm later using as follows:

server {
  listen 443 ssl;
  location /myurl {
      proxy_pass http://nodeserver;
      proxy_set_header X-Forwarded-For $remote_addr;
      proxy_set_header Cookie $cookie;

I expect this code to replace the Cookie header with the value supplied in the "My-Token" header, but what I see instead is that the value of both headers is passed through unchanged.

1 Answer 1


Your map specifies that the value you want to check is the literal string cookie. This is not what you said you want, and it's pretty useless to try to check a literal string since it can only be itself.

The first parameter to map is the value you want to test. Instead of the string cookie you should pass what you actually want to check. It seems you are looking for whether the user agent is sending a cookie. If that's the case, you should use $http_cookie.

map $http_cookie $cookie {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.