Introduction to NGINX-Four (Access Restrictions)

Nine, NGINX access restrictions

1.ngx_http_limit_req_module

(1): Enable request frequency restriction:
①: Test access without restriction:
yum install -y httpd-tools //Download pressure measurement tool
ab -n 100 -c 10 http://127.0.0.1/ //Use The stress testing tool sends 100 requests to itself, divided into 10 times
②: Introduction to NGINX-Four (Access Restrictions)
③: Start limit:
1.vim /etc/nginx/nginx.conf
2.limit_req_zone $binary_remote_addr zone=req_zone:10m rate=1r/s; // Definition
Introduction to NGINX-Four (Access Restrictions)
3. Quote: vim /etc/nginx/conf.d/default.conf
limit_req zone=req_zone;
Introduction to NGINX-Four (Access Restrictions)
4.systemctl restart nginx //Restart the service
5. Test: ab -n 100 -c 10 http://127.0.0.1 /
Introduction to NGINX-Four (Access Restrictions)
6. Observe the error log: tail -10 /var/log/nginx/error.log
Introduction to NGINX-Four (Access Restrictions)


2.ngx_http_limit_conn_module

1. Purpose: Limit the connection (TCP) by IP address. But the experimental environment cannot be tested
2. Start the connection frequency limit
(1): vim /etc/nginx/nginx.conf
(2):
http {
limit_conn_zone $binary_remote_addr zone=conn_zone:10m;
}
server {
location / {
...
limit_conn conn_zone 1;
}
}
Introduction to NGINX-Four (Access Restrictions)
Single IP, only one tcp connection is allowed at the same time
(3): yum install -y httpd-tools
(4) ab -n 100 -c 10 http://server IP address/
This is ApacheBench, Version 2.3 < $Revision: 1430300 $>
Benchmarking localhost (be patient).....done

Server Software: nginx/1.12.1
Server Hostname: tianyun.me
Server Port: 80

Document Path: /
Document Length: 671 bytes

Concurrency Level: 10 Current concurrent number
Time taken for tests: 0.006 seconds Total time consumed
Complete requests: 100 Number of completed requests
Failed requests: 0 Number of failed requests
Write errors: 0
Total transferred: 90400 bytes Total transfer size
HTML transferred: 67100 bytes http Transmission size
Requests per second: 15873.02 [#/sec] (mean) How many requests are processed per second.
(3): The TCP three-way handshake connection is too small and the effect is not obvious

Guess you like

Origin blog.51cto.com/14881339/2540105