首页 > 其他 > 详细

【随笔】nginx add_header指令的使用

时间:2014-12-20 00:36:57      阅读:413      评论:0      收藏:0      [点我收藏+]

  nginx配置文件通过使用add_header指令来设置response header。

  具体方法如下:

  add_header key value

add_header Cache-Control no-store
add_header Content-Encoding gzip

  用以改变Content-Type时比较特殊,可以在它设置了类型的同时还会指定charset,不过Content-Type和charset之间有分号,所以我们需要这样来添加。

add_header  Content-Type text/html; charset=utf-8;

  这样就可以给responent header的Content-Type添加指定的属性了。

例如:

  nginx设置:

 1 http {
 2     include       mime.types;
 3        default_type  application/octet-stream ;
 4     sendfile        on;
 5     keepalive_timeout  65;
 6 
 7     server {
 8         listen       8080;
 9         server_name  localhost;
10         index index.html index.htm;
11         root /usr/local/openresty/nginx/work;
12         
13         location ~* .(js)$ {
14             add_header  Content-Type text/javascript;charset=utf-8;
15         }
16         
17         location /dir {
18             default_type application/javascript;
19             content_by_lua_file /usr/local/openresty/nginx/work/resources/lua/index.lua;
20         }
21     }
22 }

  其中匹配所有.js文件,给其responent header的Content-Type值赋值为"text/javascript;charset=utf-8"。

 

【随笔】nginx add_header指令的使用

原文:http://www.cnblogs.com/linxiong945/p/4174262.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!