How to limit concurrent IP access between nginx and apache

WBOY
Release: 2023-05-21 20:04:09
forward
1405 people have browsed it

nginx
nginx limits the number of concurrent IPs, which also means limiting the number of simultaneous connections to the server from the same IP
1. Add limit_zone
This variable can only be used in http
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
I only limit one site , so add it to the server
vi /usr/local/nginx/conf/host/gaojinbo.com.conf
limit_conn one 10;
3. Restart nginx
killall nginx -hup

Copy code The code is as follows:

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;//Speed ​​limit
}
# serve static files
location ~ ^/(images|javascript|js|css|flash|media|static)/ {
root /data/www/wwwroot/down;
expires 30d;
}
}

apache
To enable the apache server to limit connections to the same IP address, mod_limitipconn is required. Generally requires manual compilation. However, the module author also provides some compiled modules, which can be used directly according to your own apache version.
1. Compilation method:
tar zxvf mod_limitipconn-0.xx.tar.gz
cd mod_limitipconn-0.xx
make apxs=/usr/local/apache/bin/apxs —–You need to follow your own rules here Path setting
make install apxs=/usr/local/apache/bin/apxs —–You need to set it according to your own path here
2.rpm installation method:
Download mod_limitipconn-0.xx.rpm directly
rpm -uhv mod_limitipconn-0.xx.rpm
Then confirm that the generated mod_limitipconn.so file is in the apache server module directory.
3. Edit the httpd.conf file:

Copy code The code is as follows:

extendedstatus on
loadmodule limitipconn_module modules/mod_limitipconn.so < ifmodule mod_limitipconn.c >
< ; location / > # / directory of all virtual hosts
maxconnperip 3 # Only 3 concurrent connections are allowed per IP
noiplimit image/* # No IP restrictions on images
< /location>
< location /mp3 > #/mp3 directory of all hosts
maxconnperiip 1 #Only one connection request is allowed per IP
onlyiplimit audio/mpeg video #This limit only applies to files in video and audio formats
< /location >
< /ifmodule>

The above is the detailed content of How to limit concurrent IP access between nginx and apache. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!