I have a server with nginx. And I have a lot of images - pngs and jpgs saved as files with no extension (like "123123123_321312").
When I use tag "img" in html page, I get theese messages in console:
Resource interpreted as Image but transferred with MIME type application/octet-stream: "http://xxxx/images/1350808948_997628". jquery.js:2 Resource interpreted as Image but transferred with MIME type application/octet-stream: "http://xxxx/images/1343808569_937350".
Is there a way to make nginx add header with correct mimetype of the requested file?
All MIME type information is stored in a database. The MIME database is located in the directory /usr/share/mime/ . The MIME database contains a large number of common MIME types, stored in the file /usr/share/mime/packages/freedesktop.
Nginx allows you to map file extensions to mime types. As the documentation says, it even comes with a pre built list of mime types (pasted at the end of the question). I've always trusted this list, and things work great, but now I've noticed that some types are missing.
It is a standard that indicates the nature and format of a document, file, or assortment of bytes. All web browsers use the MIME type to determine how to process a URL. Hence, it is essential that Nginx send the correct MIME type in the response’s Content-Type header.
Nginx will report text/plain if you don't define a default content type. As new content types are invented or added to web servers, web administrators may fail to add the new MIME types to their web server's configuration.
Reload/restart the Nginx service. For example, GNU/Linux user can run: Another option is to add the following directly to config file: It is also possible to override content type for given URL pattern. For example, I edited /etc/nginx/domains/cyberciti.biz/default.conf and added the following in server context: Save and close the file.
For adding a new MIME type, all it takes is editing the /etc/mime.types file. Let's say you want to add MIME type with extension .btc, then 1. Check If MIME type already exists Open a command line and enter the line below (replace btc with your extension) Now, this command will output a line, If that MIME type is already added.
You should use the default_type
directive :
server {
...
default_type text/html;
location /images/png {
default_type image/png;
}
location /images/jpg {
default_type image/jpeg;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With