MIME Types
When Nginx serves a file, it must tell the browser what kind of content it is. This is the MIME type, sent in the Content-Type header. Wrong types cause browsers to misread files.
The mime.types File
Nginx ships with a file mapping extensions to MIME types. Include it inside the http context:
http {
include mime.types;
default_type application/octet-stream;
}
include mime.types loads dozens of standard mappings, such as .html to text/html and .png to image/png.
default_type
If a file’s extension is not in the map, Nginx uses default_type. The safe fallback is:
default_type application/octet-stream;
This tells the browser the file is generic binary, so it downloads rather than guesses.
Adding Custom Types
You can add your own mappings with a types block:
types {
application/wasm wasm;
text/markdown md;
}
This serves .wasm files as application/wasm and .md as text/markdown.
Why It Matters
If a CSS file is sent as text/plain, the browser ignores the styling. If a font is sent with the wrong type, it may fail to load. Always include mime.types so the common cases just work, and add custom entries only for formats it does not cover.