types
The 'types' directive in NGINX defines MIME types based on file extensions.
Description
The types directive in NGINX is used to define the MIME types that will be assigned to files served by the web server, based on their file extensions. This directive can be specified within the http, server, or location contexts, which allows fine-grained control over how different files are handled based on their types. Each entry in the types directive consists of a file extension followed by the corresponding MIME type, allowing the server to accurately convey the content type of files to clients.
When a request is made for a file, NGINX checks the requested file's extension against the definitions provided in the types directive. If a match is found, NGINX will include the appropriate Content-Type header in the response. This ensures that the browser or any client receiving the file can interpret it correctly. For example, a .css file would typically have the MIME type text/css, while an .html file would be served with the MIME type text/html.
It's important to note that the types directive can be overridden at the server or location context levels, allowing for specific behavior in different parts of your configuration. NGINX comes with a default set of MIME types specified in the mime.types file, which can also be included using the include statement, providing a broader set of commonly used MIME types without the need for manual definitions.
Config Example
types {
text/html html;
text/css css;
application/javascript js;
image/png png;
image/jpeg jpeg jpg;
};Ensure that the MIME types are correctly defined; incorrect types can lead to improper handling of files by clients.
MIME types defined in a more specific context (server or location) override those defined in a more general context (http).
Always check for typos in file extension names or MIME type definitions to avoid issues with content delivery.