DevilKing's blog

冷灯看剑,剑上几分功名?炉香无需计苍生,纵一穿烟逝,万丈云埋,孤阳还照古陵

0%

Nginx Quick Reference

原文链接

通过map去代替allow/deny

1
2
3
4
5
6
7
8
9
10
11
12
13
14
map $remote_addr $globals_internal_map_acl {

# Status code:
# - 0 = false
# - 1 = true
default 0;

### INTERNAL ###
10.255.10.0/24 1;
10.255.20.0/24 1;
10.255.30.0/24 1;
192.168.0.0/16 1;

}

map anything

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
map $http_user_agent $device_redirect {

default "desktop";

~(?i)ip(hone|od) "mobile";
~(?i)android.*(mobile|mini) "mobile";
~Mobile.+Firefox "mobile";
~^HTC "mobile";
~Fennec "mobile";
~IEMobile "mobile";
~BB10 "mobile";
~SymbianOS.*AppleWebKit "mobile";
~Opera\sMobi "mobile";

}

if ($device_redirect = "mobile") {

return 301 https://m.domain.com$request_uri;

}

work_processes

I think for high load proxy servers (also standalone servers) good value is ALL_CORES - 1 (please test it before used).

gzip

You shouldn’t use HTTP compression on private responses when using TLS.

Compression can be (I think) okay to HTTP compress publicly available static content like css or js and HTML content with zero sensitive info (like an “About Us” page).

#####Mitigating Slow HTTP DoS attack (Closing Slow Connections)

1
2
3
4
client_body_timeout 10s;
client_header_timeout 10s;
keepalive_timeout 5s 5s;
send_timeout 10s;