Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to restrict ip concurrent access between nginx and apache

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Today, I would like to share with you the relevant knowledge points about how nginx and apache restrict concurrent access to ip. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article.

Nginx

Nginx limits the number of ip concurrency, which also means limiting the number of servers connected to the same ip at the same time.

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

two。 Add limit_conn

This variable can be used in http, server, location

I only limit one site, so add it to server

Vi / usr/local/nginx/conf/host/gaojinbo.com.conf

Limit_conn one 10

3. Restart nginx

Killall nginx-hup

The copy 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 20kb / speed limit

}

# serve static files

Location ~ ^ / (images | javascript | js | css | flash | media | static) / {

Root/ data/www/wwwroot/down

Expires 30d

}

}

Apache

To make the apache server restrict the connection to the same ip address, you need mod_limitipconn to do it. Manual compilation is generally required. However, the module author also provides some compiled modules that can be used directly according to their own version of apache.

one. Compilation method:

Tar zxvf mod_limitipconn-0.xx.tar.gz

Cd mod_limitipconn-0.xx

Make apxs=/usr/local/apache/bin/apxs-- set up here according to your own path

Make install apxs=/usr/local/apache/bin/apxs-- set up here according to your own path

2.rpm installation method:

Download mod_limitipconn-0.xx.rpm directly

Rpm-uhv mod_limitipconn-0.xx.rpm

Then make sure that the resulting mod_limitipconn.so file is in the apache server module directory.

three. Edit the httpd.conf file:

The copy code is as follows:

Extendedstatus on

Loadmodule limitipconn_module modules/mod_limitipconn.so

< ifmodule mod_limitipconn.c >

< location / >

# / directories of all virtual hosts

Maxconnperip 3 # only allows 3 concurrent connections per ip

Noiplimit image/* # does not impose ip restrictions on pictures

< /location>

< location /mp3 >

# / mp3 directory of all hosts

Maxconnperip 1 # only one connection request per ip

Onlyiplimit audio/mpeg video # this restriction applies only to files in video and audio formats

< /location >

< /ifmodule>

These are all the contents of the article "how nginx and apache restrict ip concurrent access". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report