nginx and apache limit ip concurrent access limit ip connection setting method
- 2020-05-06 12:17:48
- OfStack
nginx
nginx limits the number of ip concurrences, which also limits the number of
connections to the same ip server
1. Add limit_zone
This variable can only be used in http with
vi /usr/local/nginx/conf/nginx.conf
limit_zone one $binary_remote_addr 10m;
2. Add limit_conn
This variable can be used in http, server, location with
I restricted only one site, so I added
to server vi /usr/local/nginx/conf/host/gaojinbo.com.conf
limit_conn one 10;
3. Restart nginx
killall nginx -HUP
apache
For the apache server to restrict connections to the same IP address, mod_limitipconn is required. Manual compilation is generally required. However, the module author also provides some compiled modules that can be used directly according to their version of apache.
1. Compile mode:
tar zxvf mod_limitipconn-0.XX.tar.gz
cd mod_limitipconn-0.XX
make apxs = / usr/local/apache/bin/apxs - � set
here according to your own path make install apxs = / usr/local/apache/bin/apxs - � set
here according to your own path 2. Installation method of rpm:
Download mod_limitipconn-0. xx. rpm
directly rpm -Uhv mod_limitipconn-0.xx.rpm
Then confirm that the mod_limitipconn.so file is in the apache server module directory.
3. Edit httpd.conf file:
This article is from the "always learn" blog
nginx limits the number of ip concurrences, which also limits the number of
connections to the same ip server
1. Add limit_zone
This variable can only be used in http with
vi /usr/local/nginx/conf/nginx.conf
limit_zone one $binary_remote_addr 10m;
2. Add limit_conn
This variable can be used in http, server, location with
I restricted only one site, so I added
to server vi /usr/local/nginx/conf/host/gaojinbo.com.conf
limit_conn one 10;
3. Restart nginx
killall nginx -HUP
vi /usr/local/nginx/conf/vhosts/down.redocn.com.conf
limit_zone one $binary_remote_addr 10m;
server
{
listen 80;
server_name down.redocn.com;
index index.html index.htm index.php;
root /data/www/wwwroot/down;
error_page 404 /index.php;
# redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
#Zone limit
location / {
limit_conn one 1;
limit_rate 20k;// The speed limit
}
# serve static files
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
root /data/www/wwwroot/down;
expires 30d;
}
}
apache
For the apache server to restrict connections to the same IP address, mod_limitipconn is required. Manual compilation is generally required. However, the module author also provides some compiled modules that can be used directly according to their version of apache.
1. Compile mode:
tar zxvf mod_limitipconn-0.XX.tar.gz
cd mod_limitipconn-0.XX
make apxs = / usr/local/apache/bin/apxs - � set
here according to your own path make install apxs = / usr/local/apache/bin/apxs - � set
here according to your own path 2. Installation method of rpm:
Download mod_limitipconn-0. xx. rpm
directly rpm -Uhv mod_limitipconn-0.xx.rpm
Then confirm that the mod_limitipconn.so file is in the apache server module directory.
3. Edit httpd.conf file:
ExtendedStatus On
LoadModule limitipconn_module modules/mod_limitipconn.so < IfModule mod_limitipconn.c >
< Location / > # All virtual host / directory
MaxConnPerIP 3 # every IP Only allow 3 Two concurrent connections
NoIPLimit image/* # No pictures IP limit
< /Location>
< Location /mp3 > # All host /mp3 directory
MaxConnPerIP 1 # every IP Only one connection request is allowed
OnlyIPLimit audio/mpeg video # This restriction applies only to files in video and audio formats
< /Location >
< /IfModule>
This article is from the "always learn" blog