Nginx – Overwrite HTTP headers comming back from a web application server proxied in nginx

http-headersnginxreverse-proxy

I have a web application server reverse-proxied behind nginx 1.15 like so:

location / {
   proxy_pass https://some.awesome.IP:8080;
   proxy_set_header Host            $host;
   proxy_set_header X-Forwarded-For $remote_addr;
}
add_header Content-Security-Policy "default-src 'self'; frame-ancestor https://subdomain.domain.org 'self'";

Now this web application server thinks it would be a good idea to set the Content-Security-Policyheader to frame-ancestors 'self' – which destroys my front-end since I need to wrap that page in an iframe being hosted at https://subdomain.domain.org.

So, how can I in nginx change/overwrite/delete headers coming back from web application server before passing the response to the client? add_header is obviously ignored here.

Best Answer

It seems that adding proxy_hide_header Content-Security-Policy; did the trick.