NGINX Rate Limiting
1
2
3
4
# https://nginx.org/en/docs/http/ngx_http_limit_req_module.html
limit_req_status 429;
limit_req_zone $binary_remote_addr zone=reqzone1:10m rate=1r/s;
limit_req_zone $server_name zone=reqzone2:10m rate=100r/s;
1
2
3
4
# http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html
limit_conn_status 429;
limit_conn_zone $binary_remote_addr zone=connzone1:10m;
limit_conn_zone $server_name zone=connzone2:10m;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
server {
listen 80;
server_name _;
server_tokens off;
# DDOS protection
client_body_timeout 20s;
client_header_timeout 20s;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
# DDOS protection
limit_req zone=reqzone1 burst=10 nodelay;
limit_req zone=reqzone2 burst=10 nodelay;
limit_conn connzone1 1;
limit_conn connzone2 1000;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
This post is licensed under CC BY 4.0 by the author.