File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ ### 注意:此Nginx非官方版,此版可隐藏Server头。
2+
3+ #### 在官方的Nginx中,可在配置文件中使用如下配置,来隐藏Server头的Nginx版本信息。
4+
5+ ``` nginx
6+ http {
7+ ...
8+ server_tokens off;
9+ ...
10+ }
11+ ```
12+ #### 但是Server字段依然显示正在使用的是Nginx服务器。
13+
14+ #### 然而我并不想显示包括Nginx的一些服务器相关信息,所以我修改了Nginx的代码。
15+
16+ ``` nginx
17+ http {
18+ ...
19+ # 官方版本server_tokens可以设置为
20+ # on: 这是默认值,在 Server 头中包含完整的nginx版本信息。
21+ # off: 设置为 off 后,Server 头仅显示nginx,不显示版本信息。
22+ # build:设置为 build 后,Server 头中包含编译时指定的构建值。
23+ #
24+ # 这里注意,此Nginx在官方版基础上增加了
25+ # hide: 设置为 hide 后,http响应头中将不会有Server头。
26+ server_tokens hide;
27+ ...
28+ location / {
29+ proxy_pass http://backend_server;
30+ ...
31+ # 通过官方支持的proxy_hide_header指令
32+ # 隐藏varnish、nodejs、tomact、apache等相关的响应头
33+ proxy_hide_header Via;
34+ proxy_hide_header X-Varnish;
35+ proxy_hide_header X-Powered-By;
36+ ...
37+ }
38+ ...
39+ }
40+ ```
41+
42+ #### 下面是效果演示
43+
44+ 当` server_tokens on; ` 或未配置时
45+
46+ ![ 这是一张示例图片] ( https://github.com/bytesharky/nginx/blob/nginx-1.26/images/1720182600960.jpg?raw=true )
47+
48+ 当` server_tokens off; ` 时
49+
50+ ![ 这是一张示例图片] ( https://github.com/bytesharky/nginx/blob/nginx-1.26/images/1720182656168.jpg?raw=true )
51+
52+ 当` server_tokens hide; ` 时
53+
54+ ![ 这是一张示例图片] ( https://github.com/bytesharky/nginx/blob/nginx-1.26/images/1720182890661.jpg?raw=true )
You can’t perform that action at this time.
0 commit comments