Nginx 会根据mime type告诉浏览器如何处理服务器返回的文件,是打开还是下载。
默认的 default_type定义的是 default_type application/octet-stream;
mime type 和文件扩展名的对应关系一般放在 mime.types这个文件里,然后用 include mime.types; 来加载
mime.types文件里是用types指令来定义的
文本:
location /test {
default_type text/html;
return 200 'This is text!';
}
JSON:
location /test {
default_type application/json;
return 200 ‘{“status”:”success”,”result”:”nginx json”}’;
}
下载:
location /test {
add_header Content-Disposition “attachment;”;
}
声明:本站所有文章和图片,如无特殊说明,均为原创发布,转载请注明出处。