nginx add_header指令使用方法

Jane ·
更新时间:2024-09-20
· 778 次阅读

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。

您可能感兴趣的文章:为何要小心Nginx的add_header指令详解nginx配置教程之add_header的坑详解



add 方法 Nginx header

需要 登录 后方可回复, 如果你还没有账号请 注册新账号