Skip to content

Commit c1ed0fe

Browse files
committed
敏感文件
1 parent e8c1f6c commit c1ed0fe

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

book/04安全加固/03保护敏感资源.md

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,47 @@
1414

1515
```nginx configuration
1616
server {
17-
listen 8080;
17+
listen 8088;
1818
include /etc/nginx/conf/conf.d/deny.location;
1919
location / {
20-
root /usr/share/nginx/ddd;
20+
return 200;
2121
}
22-
...
23-
other config
24-
...
2522
}
23+
24+
```
25+
26+
`deny.location`内容如下:
27+
28+
```nginx configuration
29+
location ~* ^.*(\.(?:git|svn|hg|bak|bckp|save|old|orig|original|test|conf|cfg|dist|in[ci]|log|sql|mdb|sw[op]|htaccess|php#|php~|php_bak|aspx?|tpl|sh|bash|bin|exe|dll|jsp|out|cache|))$ {
30+
31+
# Use also rate limiting:
32+
# in server context: limit_req_zone $binary_remote_addr zone=per_ip_5r_s:5m rate=5r/s;
33+
limit_req zone=per_ip_5r_s;
34+
35+
deny all;
36+
access_log /var/log/nginx/restricted-files-access.log main;
37+
access_log /var/log/nginx/restricted-files-error.log main;
38+
39+
}
40+
```
41+
42+
测试用例:
43+
44+
```shell
45+
[root@localhost conf.d]# curl 127.0.0.1:8088/.git -I
46+
HTTP/1.1 403 Forbidden
47+
Date: Sat, 16 Oct 2021 04:31:03 GMT
48+
Content-Type: text/html; charset=utf-8
49+
Content-Length: 146
50+
Connection: keep-alive
51+
Server: Unknown
52+
53+
[root@localhost conf.d]# curl 127.0.0.1:8088/.sh -I
54+
HTTP/1.1 403 Forbidden
55+
Date: Sat, 16 Oct 2021 04:31:38 GMT
56+
Content-Type: text/html; charset=utf-8
57+
Content-Length: 146
58+
Connection: keep-alive
59+
Server: Unknown
2660
```

rpmbuild/SOURCES/nginx.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ http {
2222
large_client_header_buffers 4 512k;
2323
default_type application/octet-stream;
2424

25+
# limit
26+
limit_req_zone $binary_remote_addr zone=per_ip_5r_s:5m rate=5r/s;
27+
2528
index index.php index.htm index.html;
2629

2730
#web security

0 commit comments

Comments
 (0)