nginx location 配置返回文本

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;”;
}
声明:本站所有文章和图片,如无特殊说明,均为原创发布,转载请注明出处。
随机推荐
Express 使用 cors 模块支持跨域
Node.js 安装
Wordpress 使用 tag 标签获取文章列表的方法
HTML input range 数值范围选择器
JavaScript 的历史
JavaScript 类操作 classList
CSS 基本语法
JavaScript screen对象