NGINX config proxy_set_header

configurationnginx

How configurate nginx to set proxy_set_header for all domains, but not for everyone?

Best Answer

I include a global proxy configuration (e.g. /etc/nginx/conf.d/02_proxy.conf) at the end of Nginx's main configuration file (/etc/nginx/nginx.conf):

...

events {
  worker_connections 1024;
  use epoll;
}

http {
  include /etc/nginx/mime.types;
  default_type application/octet-stream;

  ...

  include /etc/nginx/conf.d/*.conf;
  include /etc/nginx/sites-enabled/*;
}

From the Nginx documentation:

The proxy_set_header directives are inherited from the previous level if and only if there are no proxy_set_header directives defined on the current level.

This means you can use a custom header on the server or location level to overwrite all global headers:

server {

  ...

  proxy_set_header X-RESET-CUSTOM-HEADERS true;

  ...
}

If you use additional proxy_set_header on the server or location level and want to keep the global ones, you must import this file again on that level.