proxy_pass_request_headers

The `proxy_pass_request_headers` directive controls whether or not NGINX will pass the proxy request headers to the proxied server. — NGINX HTTP Core

proxy_pass_request_headers
httpserverlocation
Синтаксисproxy_pass_request_headers on | off;
По умолчаниюon
Контекстhttp, server, location
МодульNGINX HTTP Core
Аргументыflag

Описание

The `proxy_pass_request_headers` directive is used to specify whether the incoming headers of the original request should be forwarded to the proxied server. This directive can be set to a flag value of either `on` or `off`. When enabled, all headers received by NGINX from the client will be included in the request that is sent to the proxied upstream server. This can be particularly useful when you need to preserve client information like authentication tokens or custom headers that the upstream application needs to function properly. In practical scenarios, it ensures that fields like `User-Agent`, `Referer`, and any custom headers are included, which can be critical for maintaining application behaviors depending on these values. If set to `off`, these headers will not be passed, which may lead to unexpected behavior depending on the application logic that relies on these headers. This directive can be applied in several contexts: http, server, and location blocks, allowing flexibility in configuration based on different handling needs or contexts. It's important to note that while this directive allows for fine-tuning how requests are processed, care should be taken to avoid passing sensitive information to external servers, as doing so could expose user data or compromise security in certain configurations.

Пример конфига

location /api {
    proxy_pass http://backend;
    proxy_pass_request_headers off;
}

Ensure that sensitive headers are not inadvertently sent to proxied servers, especially when configured to `on`.

This directive's behavior is overridden by directives that explicitly clear or modify headers after it is set.