more_clear_headers

The `more_clear_headers` directive removes specified HTTP response headers from the outgoing response.

Syntaxmore_clear_headers header1 [header2 ...];
Defaultnone
Contexthttp, server, location, if in location
Arguments1+

Description

The more_clear_headers directive is part of the NGINX Headers More dynamic module, which extends the functionality of NGINX by allowing advanced control over HTTP headers. This directive allows you to clear or remove specific headers from the response sent to the client. It can be used to eliminate unwanted default headers such as Server, X-Powered-By, and others, which may disclose information that developers prefer to keep hidden for security or compliance reasons.

When you use more_clear_headers, you can specify one or more header names as arguments. Each specified header will be removed from the response, and you can use multiple more_clear_headers directives consecutively to clear multiple headers at once. The directive can be used in various contexts including http, server, location, and even inside an if directive within a location, making it quite flexible for different configuration needs. It's important to note that the header names specified are case-insensitive, meaning you should use the appropriate name regardless of its case as HTTP headers are typically case-insensitive.

If you want to clear headers conditionally based on specific criteria such as MIME types or response status codes, you might combine this directive with other related directives. However, keep in mind that more_clear_headers does not allow for additional filtering criteria by MIME type or status codes, as seen with some of the other commands in the module such as more_set_headers which has more advanced options.

Config Example

location /example {
    more_clear_headers 'X-Powered-By';
    more_clear_headers 'Server';
}

Ensure there are no typos in header names, as they are case-insensitive but must match exactly from the response.

Using this directive in the wrong context may lead to unexpected behavior, particularly within nested locations or if directives.

Removing certain headers may affect the functionality or security features of your application.

← Back to all directives