To override the content type of a file with Nginx, you can use the types
directive in the http
block of your Nginx configuration file. The types
directive allows you to specify the MIME type of a file based on its extension.
Here is an example of how you can use the types
directive to override the content type of a file:
http { types { text/html html htm shtml; text/css css; application/javascript js; application/json json; application/octet-stream bin deb exe dll; image/gif gif; image/jpeg jpeg jpg; image/png png; image/svg+xml svg; audio/mpeg mp3; audio/ogg ogg; audio/x-flac flac; video/mpeg mpeg mpg; video/mp4 mp4; video/x-flv flv; video/x-ms-wmv wmv; text/csv csv; application/x-yaml yaml yml; } }
In this example, the types
directive specifies the MIME type for various file extensions. For example, the MIME type for .html
files is text/html
, and the MIME type for .css
files is text/css
.
To override the content type for a specific file, you can use the default_type
directive in the server
block of your Nginx configuration file. Here is an example of how you can use the default_type
directive to override the content type of a file:
server { default_type application/octet-stream; ... }
In this example, the default_type
directive specifies that the content type for all files in the server block should be application/octet-stream
.