zoukankan      html  css  js  c++  java
  • 【随笔】nginx add_header指令的使用

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

  • 相关阅读:
    Linux查看系统信息
    pgrep 和 pkill 使用小记
    linux下json库的编译及例程
    Epoll 实例
    gcc中的内嵌汇编语言
    BZOJ 1053: [HAOI2007]反素数ant
    2018.7.15模拟赛
    BZOJ 2002: [Hnoi2010]Bounce 弹飞绵羊
    BZOJ 4241: 历史研究
    LUOGU P2365 任务安排
  • 原文地址:https://www.cnblogs.com/linxiong945/p/4174262.html
Copyright © 2011-2022 走看看