欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

nginx add_header指令使用方法

程序员文章站 2023-11-20 12:11:58
response header一般都是以key:value的形式,例如:“content-encoding:gzip、cache-control:no-store”,设置的...

response header一般都是以key:value的形式,例如:“content-encoding:gzip、cache-control:no-store”,设置的命令为:

复制代码 代码如下:

add_header cache-control no-store
add_header content-encoding gzip

但是有一个十分常用的response header比较特性,就是content-type,可以在它设置了类型的同时还会指定charset,例如:“text/html; charset=utf-8”,由于其存在分号,而分号在配置文件中作为结束符,所以在配置的时候需要用引号把其引起来,配置如下:

复制代码 代码如下:

add_header  content-type 'text/html; charset=utf-8';

另外由于没有单独设置charset的key,所以要设置响应的charset就需要使用content-type来指定charset。