Skip to content

Commit bb1be75

Browse files
committed
添加隐藏header文件
1 parent c1ed0fe commit bb1be75

File tree

6 files changed

+92
-13
lines changed

6 files changed

+92
-13
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,21 @@
3939
- [ ] [upstream开启keepalive](book/03配置调优/09upstream开启keepalive.md)
4040
- [ ] [尽可能精准配置location](book/03配置调优/10尽可能精准配置location.md)
4141
- 加固列表
42-
- [x] 安装最新版nginx
42+
- [x] 安装最新版`nginx`
43+
- [x] 使用最新版本`openssl`
4344
- [x] [使用非特权用户运行nginx](book/04安全加固/02使用非特权用户运行nginx.md)
45+
- [x] [隐藏版本信息](book/04安全加固/04隐藏nginx版本信息.md)
4446
- [ ] [保护敏感资源](book/04安全加固/03保护敏感资源.md)
47+
- [ ] ssl加固(TODO)
48+
49+
50+
## TODO
51+
52+
- [ ] 自定义异常页
53+
- [ ] lua块
54+
- [ ] waf功能
55+
- [ ] 全局黑名单
56+
- [ ] debug
4557

4658
### 构建介质
4759

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
### 隐藏版本信息
2+
[Hide Nginx version number](https://github.com/trimstray/nginx-admins-handbook/blob/master/doc/RULES.md#rationale-39)
3+
- [更多nginx文档](https://weiliang-ms.github.io/nginx/)
4+
- [更多linux相关文档](https://weiliang-ms.github.io/wl-awesome/)
5+
6+
> 隐藏版本信息(已内置)
7+
8+
```nginx configuration
9+
server_tokens off;
10+
```
11+
12+
> 修改`server`信息(已内置)
13+
14+
```nginx configuration
15+
more_set_headers "Server: Unknown";
16+
```
17+
18+
> 错误页
19+
20+
TODO
21+
22+

book/04安全加固/05配置ACL规则.md

Whitespace-only changes.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
### 隐藏上游代理报头
2+
3+
[Hide upstream proxy headers](https://github.com/trimstray/nginx-admins-handbook/blob/master/doc/RULES.md#rationale-41)
4+
- [更多nginx文档](https://weiliang-ms.github.io/nginx/)
5+
- [更多linux相关文档](https://weiliang-ms.github.io/wl-awesome/)
6+
7+
`nginx`被用来反向代理上游服务器(比如一个`PHP-fpm`实例)时,
8+
隐藏在上游响应中发送的某些报头(比如PHP运行的版本)是有益的。
9+
10+
可以使用`proxy_hide_header`(或Lua模块)来隐藏/删除上游服务器返回到你的`nginx`反向代理(并最终返回到客户端)的头文件。
11+
12+
> 使用方式
13+
14+
代理`http`服务的`location`块添加`include /etc/nginx/conf/conf.d/hide-headers.rule;`配置
15+
16+
```nginx configuration
17+
upstream ddd-server {
18+
server 11.11.11.11:80;
19+
server 11.11.11.12:80;
20+
}
21+
server {
22+
listen 8081;
23+
location /ddd {
24+
include /etc/nginx/conf/conf.d/hide-headers.rule;
25+
proxy_pass http://ddd-server;
26+
}
27+
}
28+
```
29+
30+
`/etc/nginx/conf/conf.d/hide-headers.rule`:
31+
32+
```nginx configuration
33+
proxy_hide_header X-Application-Context;
34+
proxy_hide_header Access-Control-Allow-Origin;
35+
proxy_hide_header X-Powered-By;
36+
proxy_hide_header X-AspNetMvc-Version;
37+
proxy_hide_header X-Drupal-Cache;
38+
proxy_hide_header X-Powered-By;
39+
proxy_hide_header Server;
40+
proxy_hide_header X-AspNet-Version;
41+
proxy_hide_header X-Drupal-Dynamic-Cache;
42+
proxy_hide_header X-Generator;
43+
proxy_hide_header X-Runtime;
44+
proxy_hide_header X-Rack-Cache;
45+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
proxy_hide_header X-Application-Context;
2+
proxy_hide_header Access-Control-Allow-Origin;
3+
proxy_hide_header X-Powered-By;
4+
proxy_hide_header X-AspNetMvc-Version;
5+
proxy_hide_header X-Drupal-Cache;
6+
proxy_hide_header X-Powered-By;
7+
proxy_hide_header Server;
8+
proxy_hide_header X-AspNet-Version;
9+
proxy_hide_header X-Drupal-Dynamic-Cache;
10+
proxy_hide_header X-Generator;
11+
proxy_hide_header X-Runtime;
12+
proxy_hide_header X-Rack-Cache;

rpmbuild/SOURCES/conf/conf.d/http.proxy

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,4 @@ add_header Cache-Control "no-cache, no-store";
1010
add_header Referrer-Policy "same-origin";
1111
add_header X-XSS-Protection "1; mode=block";
1212
add_header X-Content-Type-Options "nosniff";
13-
proxy_hide_header X-Application-Context;
14-
proxy_hide_header Access-Control-Allow-Origin;
15-
proxy_hide_header X-Powered-By;
16-
proxy_hide_header X-AspNetMvc-Version;
17-
proxy_hide_header X-Drupal-Cache;
18-
proxy_hide_header X-Powered-By;
19-
proxy_hide_header Server;
20-
proxy_hide_header X-AspNet-Version;
21-
proxy_hide_header X-Drupal-Dynamic-Cache;
22-
proxy_hide_header X-Generator;
23-
proxy_hide_header X-Runtime;
24-
proxy_hide_header X-Rack-Cache;
2513

0 commit comments

Comments
 (0)