nginx – Injecting parameters from URL to reverse proxy via proxy_set_header

I’m passing a cookie to the remote server using the following block:

location /
    set $foo "bla=mla";
    set $bar "$arg_user=$arg_pass";

    proxy_pass http://remoteserver:8117/;
    proxy_connect_timeout 3600s;
    proxy_read_timeout 3600s;
    proxy_send_timeout 3600s;
    proxy_redirect off;
    proxy_buffering off;
    proxy_http_version 1.1;
    proxy_cache_bypass 1; 
    proxy_no_cache 1;
    proxy_hide_header Set-Cookie;
    proxy_ignore_headers Set-Cookie;
    proxy_set_header Cookie "$foo";
    proxy_set_header Connection "upgrade";
    proxy_set_header Origin http://$host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    add_header X-uri "$foo";

This works fine.

However, when I try to build the $foo using the arguments in the URL, it fails.

Example URL:


Config Change:

proxy_set_header Cookie "$bar";

X-uri test header has the exact same value for both $foo and $bar.