Nginx Proxy_Hide_Header and Variable

I need to hide some headers for a specific path. I have the following nginx config:

server {
  listen 80;

  location / {
    set $x_hide_header "X-Foo-Bar";

    if ($uri ~ "some-path$") {
      set $x_hide_header "Header-I-Need-To-Hide";
    }

    proxy_hide_header $x_hide_header;
    proxy_pass 
  }
}

But the header still exists. If I add proxy_hide_header "Header-I-Need-To-Hide" it disappears, but I need to hide it only for a specific path, as was said above. Looks like nginx interprets the variable in proxy_hide_header as string literal. Is there any workaround?

I can do this by defining another location and copying all from the current one + proxy_hide_header, but I won't do this. Maybe there is another solution?

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article