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
< ; location / > # / directory of all virtual hosts
maxconnperip 3 # Only 3 concurrent connections are allowed per IP
noiplimit image/* # No IP restrictions on images
#/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
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!

NGINXUnit can be used to deploy and manage applications in multiple languages. 1) Install NGINXUnit. 2) Configure it to run different types of applications such as Python and PHP. 3) Use its dynamic configuration function for application management. Through these steps, you can efficiently deploy and manage applications and improve project efficiency.

NGINX is more suitable for handling high concurrent connections, while Apache is more suitable for scenarios where complex configurations and module extensions are required. 1.NGINX is known for its high performance and low resource consumption, and is suitable for high concurrency. 2.Apache is known for its stability and rich module extensions, which are suitable for complex configuration needs.

NGINXUnit improves application flexibility and performance with its dynamic configuration and high-performance architecture. 1. Dynamic configuration allows the application configuration to be adjusted without restarting the server. 2. High performance is reflected in event-driven and non-blocking architectures and multi-process models, and can efficiently handle concurrent connections and utilize multi-core CPUs.

NGINX and Apache are both powerful web servers, each with unique advantages and disadvantages in terms of performance, scalability and efficiency. 1) NGINX performs well when handling static content and reverse proxying, suitable for high concurrency scenarios. 2) Apache performs better when processing dynamic content and is suitable for projects that require rich module support. The selection of a server should be decided based on project requirements and scenarios.

NGINX is suitable for handling high concurrent requests, while Apache is suitable for scenarios where complex configurations and functional extensions are required. 1.NGINX adopts an event-driven, non-blocking architecture, and is suitable for high concurrency environments. 2. Apache adopts process or thread model to provide a rich module ecosystem that is suitable for complex configuration needs.

NGINX can be used to improve website performance, security, and scalability. 1) As a reverse proxy and load balancer, NGINX can optimize back-end services and share traffic. 2) Through event-driven and asynchronous architecture, NGINX efficiently handles high concurrent connections. 3) Configuration files allow flexible definition of rules, such as static file service and load balancing. 4) Optimization suggestions include enabling Gzip compression, using cache and tuning the worker process.

NGINXUnit supports multiple programming languages and is implemented through modular design. 1. Loading language module: Load the corresponding module according to the configuration file. 2. Application startup: Execute application code when the calling language runs. 3. Request processing: forward the request to the application instance. 4. Response return: Return the processed response to the client.

NGINX and Apache have their own advantages and disadvantages and are suitable for different scenarios. 1.NGINX is suitable for high concurrency and low resource consumption scenarios. 2. Apache is suitable for scenarios where complex configurations and rich modules are required. By comparing their core features, performance differences, and best practices, you can help you choose the server software that best suits your needs.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools