When NGINX serves a static file, how does it decide which MIME type to send in the Content-Type header if no explicit type is set?
Think about how web servers usually identify file types for HTTP headers.
NGINX uses the file extension and the mime.types file to map extensions to MIME types. This allows it to send the correct Content-Type header for known file types.
Given this NGINX configuration snippet:
http {
include mime.types;
default_type application/octet-stream;
}
server {
listen 8080;
location / {
root /usr/share/nginx/html;
}
}If a client requests file.xyz (an unknown extension), what Content-Type header will NGINX send?
Consider what default_type is set to and what happens if the extension is unknown.
If the file extension is not found in mime.types, NGINX uses the default_type directive value, which here is application/octet-stream.
You want NGINX to send text/plain as the default MIME type for files with unknown extensions. Which configuration snippet achieves this?
The order of directives matters and default_type must have a valid value.
Setting default_type text/plain; after including mime.types correctly sets the default MIME type for unknown extensions.
An NGINX server is sending Content-Type: text/html for every file, including images and CSS. The config includes include mime.types; and default_type application/octet-stream;. What is the most likely cause?
Think about what happens if the MIME types file is not loaded properly.
If the mime.types file is missing or empty, NGINX falls back to default_type (application/octet-stream). Since text/html is being sent instead, default_type must be overridden elsewhere (e.g., in server or location context).
Consider this NGINX http block:
http {
default_type application/json;
include mime.types;
}What MIME type will NGINX send for a .css file request?
NGINX prioritizes MIME type lookup from the types map (mime.types) before using default_type.
NGINX looks up the file extension in the MIME types map from mime.types. The .css extension maps to text/css, so that is used. The default_type directive is only for unmatched extensions, and directive order does not affect known mappings.