addition_types

The 'addition_types' directive allows users to specify custom MIME types to be added to the response's Content-Type header based on file extension.

Syntaxaddition_types extension mime_type [extension mime_type ...];
Defaultnone
Contexthttp, server, location
Arguments1+

Description

The 'addition_types' directive in NGINX is used to map file extensions to custom MIME types that should be added to the Content-Type header of HTTP responses. This directive allows web server administrators to handle file types that are not covered by the default MIME type definitions, ensuring correct content delivery based on the file type.

The syntax for 'addition_types' requires at least one argument, which consists of a file extension followed by a MIME type. Multiple extensions and their corresponding MIME types can be defined in a single directive. When a file is served, NGINX checks the specified extensions against the requested file. If a match is found, the corresponding MIME type is included in the response, supplementing the pre-defined types in the NGINX configuration.

This directive can be used in various contexts such as http, server, or location blocks, giving flexibility in configuring MIME types for different parts of your web application. The addition of custom MIME types can help prevent issues with file handling on the client side, ensuring browsers properly interpret the content of the files being delivered.

Config Example

http {
    addition_types .json application/json;
    addition_types .xml application/xml;
}

Ensure that the MIME type specified is valid and recognized by browsers.

Be cautious of overriding existing MIME types inadvertently by using the same extension with a different type.

This directive does not revert back to default types automatically; specify all needed types explicitly.

← Back to all directives