Nginx增加mime类型 修改mime type类型默认打开方式的方法

Nginx的mime type Nginx 会根据mime type定义的对应关系来告诉浏览器如何处理服务器传给浏览器的这个文件,是打开还是下载;如果Web程序没设置, Nginx也没对应文件的扩展名,就用Nginx 里默认的 default_type定义的处理方式。 比如Nginx默认的配置中default

Nginx的mime type

Nginx 会根据mime type定义的对应关系来告诉浏览器如何处理服务器传给浏览器的这个文件,是打开还是下载;如果Web程序没设置,

Nginx也没对应文件的扩展名,就用Nginx 里默认的 default_type定义的处理方式。

比如Nginx默认的配置中default_type application/octet-stream; 这个就是默认为下载,浏览器访问到未定义的扩展名的时候,就默认为下载

该文件;如果将这个设置改成default_type text/html;那就是告诉浏览器默认的打开方式是把所有未设置的扩展名当HTML文件打开

,虽然可能这样设置会很多打不开。

mime type 和文件扩展名的对应关系一般放在 mime.types这个文件里,然后用 include mime.types; 来加载

mime.types文件里是用types指令来定义的,下面是一个完整的定义:

 

types {
# Audio
audio/midi mid midi kar;
audio/mp4 aac f4a f4b m4a;
audio/mpeg mp3;
audio/ogg oga ogg opus;
audio/x-realaudio ra;
audio/x-wav wav;
# Images
image/bmp bmp;
image/gif gif;
image/jpeg jpeg jpg;
image/png png;
image/svg+xml svg svgz;
image/tiff tif tiff;
image/vnd.wap.wbmp wbmp;
image/webp webp;
image/x-icon ico cur;
image/x-jng jng;
# JavaScript
application/javascript js;
application/json json;
# Manifest files
application/x-web-app-manifest+json webapp;
text/cache-manifest manifest appcache;
# Microsoft Office
application/msword doc;
application/vnd.ms-excel xls;
application/vnd.ms-powerpoint ppt;
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx;
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx;
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx;
# Video
video/3gpp 3gpp 3gp;
video/mp4 mp4 m4v f4v f4p;
video/mpeg mpeg mpg;
video/ogg ogv;
video/quicktime mov;
video/webm webm;
video/x-flv flv;
video/x-mng mng;
video/x-ms-asf asx asf;
video/x-ms-wmv wmv;
video/x-msvideo avi;
# Web feeds
application/xml atom rdf rss xml;
# Web fonts
application/font-woff woff;
application/font-woff2 woff2;
application/vnd.ms-fontobject eot;
application/x-font-ttf ttc ttf;
font/opentype otf;
# Other
application/java-archive jar war ear;
application/mac-binhex40 hqx;
application/pdf pdf;
application/postscript ps eps ai;
application/rtf rtf;
application/vnd.wap.wmlc wmlc;
application/xhtml+xml xhtml;
application/vnd.google-earth.kml+xml kml;
application/vnd.google-earth.kmz kmz;
application/x-7z-compressed 7z;
application/x-chrome-extension crx;
application/x-opera-extension oex;
application/x-xpinstall xpi;
application/x-cocoa cco;
application/x-java-archive-diff jardiff;
application/x-java-jnlp-file jnlp;
application/x-makeself run;
application/x-perl pl pm;
application/x-pilot prc pdb;
application/x-rar-compressed rar;
application/x-redhat-package-manager rpm;
application/x-sea sea;
application/x-shockwave-flash swf;
application/x-stuffit sit;
application/x-tcl tcl tk;
application/x-x509-ca-cert der pem crt;
application/x-bittorrent torrent;
application/zip zip;
application/octet-stream bin exe dll;
application/octet-stream deb;
application/octet-stream dmg;
application/octet-stream iso img;
application/octet-stream msi msp msm;
application/octet-stream safariextz;
text/css css;
text/html html htm shtml;
text/mathml mml;
text/plain txt;
text/vnd.sun.j2me.app-descriptor jad;
text/vnd.wap.wml wml;
text/vtt vtt;
text/x-component htc;
text/x-vcard vcf;
}

一般在Nginx的配置文件nginx.conf里面的http{}字段中配置即可,注意mime.types是在你的nginx的安装目录下,如果目录不是下面的,那你要自己手工修改:

# Define the MIME types for files.
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Update charset_types due to updated mime.types
charset_types text/xml text/plain text/vnd.wap.wml application/x-javascript application/rss+xml text/css application/javascript application/json;

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

我在使用Nginx+php基于ThinkPHP学习时,基于PATHINFO访问直接出现404错误,原来是Nginx不支持。下面分享一下解决方式 ThinkPHP采用单一入口模式访问应用,下面的访问是等效的: http://serverName/index.php http://serverName/index.php/Home/Index/index
总体架构: 前端web服务器+数据库服务器+文件转换服务器+文件存储服务器 总体描述: 前端web页面上传文件,后端程序将数据写入mysql,并将文件发送到文件服务器,文件服务器定时查询mysql取出需要转换文件列表,用php脚本调用linux命令执行转换文件操作,转换
跟版素材网(www.genban.org)提供nginx,php,等网页设计素材资源,提供相关网页设计资源的教程和免费下载。跟版网,专业织梦网页设计模板资源站。。