proxy_pass_header
The `proxy_pass_header` directive specifies which headers should be passed from the proxied server to the client.
Description
The proxy_pass_header directive is used within the context of http, server, or location blocks in NGINX configuration files. This directive allows the user to indicate specific HTTP headers that should be included in the HTTP response from the NGINX server to the client when the response is generated from a proxied server. By default, NGINX will pass certain headers from the upstream server to the client, but the proxy_pass_header directive gives users the flexibility to add or restrict specific headers based on their needs. This can be particularly useful in managing security, caching behavior, or customizing responses based on the environment.
When using proxy_pass_header, multiple headers can be specified, allowing fine-tuning of which headers need to be passed through. For example, if a proxied server sets a custom header that clients need to receive, this directive can ensure that the header is forwarded along with the response back to the originating client. Conversely, if there are headers that should not be shared due to security or privacy concerns, this directive can be used to control that behavior. It’s important to understand the implications of manipulating headers, especially in terms of security context, caching, and client compatibility.
Config Example
location /api {
proxy_pass http://backend;
proxy_pass_header X-Custom-Header;
}Ensure the specified headers exist in the response from the upstream server; otherwise, they will not be passed to the client.
Using too many headers can increase response size, so only pass what is necessary.