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版后支持