zoukankan      html  css  js  c++  java
  • nginx---隐藏或添加后端服务器的信息

    proxy_hide_header field;
      用于隐藏后端服务器特定的响应首部,默认nginx在响应报文中不传递后端服务器的首部字段Date, Server, X-Pad, X-Accel等

    测试访问:

    curl www.test.net/api/m.html -L -I
    HTTP/1.1 200 OK
    Server: nginx/1.20.1
    Date: Tue, 08 Jun 2021 06:25:15 GMT
    Content-Type: text/html; charset=UTF-8
    Content-Length: 601019
    Connection: keep-alive
    Last-Modified: Tue, 08 Jun 2021 05:06:29 GMT
    ETag: "92bbb-5c43a1ef0c1ab"
    Accept-Ranges: bytes
    ETag: "92bbb-5c43a1ef0c1ab" 这一段不希望被别人看到
      1、修改配置文件
    vim /etc/nginx/conf.d/test.conf 

    在server字段,任意位置添加如下:

      proxy_hide_header Etag;

      2、重启服务

    1 nginx -s stop 
    2 nginx

      3、测试访问

    curl www.test.net/api/m.html -L -I
    HTTP/1.1 200 OK
    Server: nginx/1.20.1
    Date: Tue, 08 Jun 2021 06:29:43 GMT
    Content-Type: text/html; charset=UTF-8
    Content-Length: 601019
    Connection: keep-alive
    Last-Modified: Tue, 08 Jun 2021 05:06:29 GMT
    Accept-Ranges: bytes

    proxy_pass_header field;
      默认nginx在响应报文中不传递后端服务器的首部字段Date, Server, X-Pad, X-Accel等参数,如果要传递的话则要使用 proxy_pass_header field声明将后端服务器返回的值传递给客户端

      

     1、修改配置文件
    vim /etc/nginx/conf.d/test.conf 

    在server字段,任意位置添加如下:

      proxy_hide_header Server;

      2、重启服务

    1 nginx -s stop 
    2 nginx

      3、测试访问

    curl www.test.net/api/m.html -L -I
    HTTP/1.1 200 OK
    Date: Tue, 08 Jun 2021 06:32:42 GMT
    Content-Type: text/html; charset=UTF-8
    Content-Length: 601019
    Connection: keep-alive
    Server: Apache/2.4.6 (CentOS)
    Last-Modified: Tue, 08 Jun 2021 05:06:29 GMT
    Accept-Ranges: bytes

    会显示后端服务器的版本号


    自定义缓存信息:
      查看缓存的命中率:add_header X-Cache $upstream_cache_status; 缓存的命中率
    在server字段,任意位置添加如下:
    add_header X-Cache $upstream_cache_status; 

    1、测试访问

    curl www.test.net/api/m.html -L -I
    HTTP/1.1 200 OK
    Date: Tue, 08 Jun 2021 07:06:58 GMT
    Content-Type: text/html; charset=UTF-8
    Content-Length: 601019
    Connection: keep-alive
    Server: Apache/2.4.6 (CentOS)
    Last-Modified: Tue, 08 Jun 2021 05:06:29 GMT
    X-Cache: MISS
    Accept-Ranges: bytes

    2、再次测试访问

    curl www.test.net/api/m.html -L -I
    HTTP/1.1 200 OK
    Date: Tue, 08 Jun 2021 07:08:09 GMT
    Content-Type: text/html; charset=UTF-8
    Content-Length: 601019
    Connection: keep-alive
    Server: Apache/2.4.6 (CentOS)
    Last-Modified: Tue, 08 Jun 2021 05:06:29 GMT
    X-Cache: HIT
    Accept-Ranges: bytes

      第一次没有利用缓存,后面缓存利用率就是HIT了

      保持访问响应缓存的状态(0.8.3)。状态可以是 “MISS”, “BYPASS”, “EXPIRED”, “STALE”, “UPDATING”, “REVALIDATED”, or “HIT”.

    代理服务器nginx的IP地址:add_header X-Via $server_addr;
    代理服务器的主机名:add_header X-Accel $server_name;
     X-Via和X-Accel都是自定义的字段,可以自己随便定义

      add_trailer name value [always];
      添加自定义响应信息的尾部, 1.13.2版后支持

     


    ------------------------------------------------------------------------------------------------------------------------- ------------------------------------------------------- 博客均为个人笔记,无所追求,仅供参考~~~ QQ--2382990774
  • 相关阅读:
    inux修改profile文件出错后所有命令不能用
    windows常用批处理脚本
    Namespace + functions versus static methods on a class 命名空间函数和类的静态方法对比
    vs2008(visual studio)使用cppcheck
    保存文件为UTF8格式(Writing UTF8 files in C++).
    C++ smtp发送邮件类(ssl/tls)转自codeproject。
    CString、TCHAR、WCHAR 字符串等转BSTR的几种方法。
    C/C++中全局变量的那些事儿
    [C++] 哪本书是对程序员最有影响、每个程序员都该阅读的书?读书排行。
    (转)修改VS2008(vc)中工程/解决方案/类的名字
  • 原文地址:https://www.cnblogs.com/alexlv/p/14862722.html
Copyright © 2011-2022 走看看