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

  • 相关阅读:
    git
    *** errRun
    Centos与Debian的安装命令
    HTML基础
    基本的SQL语言
    phpstudy靶场搭建
    Centos7下搭建服务器(apache+mysql+php)
    Centos7设置yum源
    Linux基础
    一个服务器中搭建多个站点
  • 原文地址:https://www.cnblogs.com/linxiong945/p/4174262.html
Copyright © 2011-2022 走看看