在Apache2中,您可以使用mod_evasive模块来限制访问频率。以下是如何安装和配置mod_evasive的步骤:
mod_evasive模块:对于Debian/Ubuntu系统,请运行以下命令:
sudo apt-get update
sudo apt-get install libapache2-mod-evasive
对于CentOS/RHEL系统,请运行以下命令:
sudo yum install mod_evasive
mod_evasive模块:对于Debian/Ubuntu系统,请运行以下命令:
sudo a2enmod evasive
对于CentOS/RHEL系统,请运行以下命令:
sudo systemctl enable mod_evasive
mod_evasive:编辑Apache配置文件(例如/etc/apache2/apache2.conf或/etc/httpd/conf/httpd.conf),并添加以下内容:
<IfModule mod_evasive20.c>
DOSHashTableSize 3097
DOSPageCount 2
DOSSiteCount 50
DOSPageInterval 1
DOSSiteInterval 1
DOSBlockingPeriod 10
</IfModule>
这里的配置表示:
您可以根据需要调整这些值。
对于Debian/Ubuntu系统,请运行以下命令:
sudo systemctl restart apache2
对于CentOS/RHEL系统,请运行以下命令:
sudo systemctl restart httpd
现在,mod_evasive模块已经配置完成并生效。它将限制访问频率,防止恶意用户对您的网站发起大量请求。