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"。

 

posted on 2014-12-19 23:40  linxiong  阅读(36561)  评论(1编辑  收藏  举报