more_clear_input_headers

The `more_clear_input_headers` directive removes specified input headers from incoming requests.

Syntaxmore_clear_input_headers header_name [header_name ...];
Defaultnone
Contexthttp, server, location, if in location
Arguments1+

Description

The more_clear_input_headers directive is part of the NGINX Headers More dynamic module, which enhances NGINX's ability to manipulate HTTP headers. This directive allows users to specify one or more headers that should be removed from the input HTTP request. It is particularly useful in scenarios where certain headers are not needed for application processing or could interfere with backend processes or security protocols. The directive can accept multiple header names as arguments, allowing for the convenient clearing of several headers in a single declaration.

In terms of configuration context, this directive can be utilized within the http, server, location, or even within if conditions inside a location. When used in a configuration block, the specified headers are cleared for requests that enter that block. It's important to note that the directive only removes headers that are present in incoming requests; if a specified header is missing, there is no effect. The header names are case-insensitive, meaning that 'X-MyHeader' and 'x-myheader' will be treated as the same. This provides flexibility in header management within NGINX environments.

For users looking to maintain clean header management and thus control data passed to backend services, this directive is a key component. It's especially vital when working with APIs or microservices that require a precise request format, ensuring no unwanted data is carried over into processing stages.

Config Example

location /api {
    more_clear_input_headers 'X-Unwanted-Header';
    more_clear_input_headers 'X-May-Contain-Sensitive-Data';
}

Ensure the headers you are trying to clear exist in the request; if not, there will be no effect.

Be cautious when clearing headers like 'Authorization' or 'Content-Type' as it may disrupt application functionality.

Using this directive within an 'if' block can lead to complex behaviors; ensure you test thoroughly.

← Back to all directives