sub_filter_types

The 'sub_filter_types' directive configures the content types that will be subject to response body substitutions in NGINX.

Syntaxsub_filter_types mime_type ...;
Defaultnone
Contexthttp, server, location
Arguments1+

Description

The 'sub_filter_types' directive allows you to specify which MIME types should be processed for body substitutions using the 'sub_filter' directive within NGINX. By default, response bodies of specific content types can be modified according to user-defined substitutions, such as replacing specific strings with others. This directive becomes essential when you want to limit or control which types of content are processed for such substitutions, which can help optimize performance and resource usage.

The use of 'sub_filter_types' helps in preventing unnecessary processing of content types that do not require substitution and can improve the efficiency of the NGINX server. It accepts one or more MIME types as arguments. Each type is specified within the directive and can include standard types such as 'text/html', 'text/css', 'application/json', etc. The defined types in 'sub_filter_types' will determine the context in which the corresponding 'sub_filter' directives operate, ensuring that only the appropriate responses are modified.

Config Example

http {
    sub_filter_types text/html text/css;
}

If no MIME types are defined, the default behavior may apply, leading to unintended substitutions.

Only the MIME types specified will be subject to filtering; ensure you list all needed types for your application.

Substitution occurs only on selected content types, which may require careful consideration of what types to include.

← Back to all directives