找到apche的配置文件 一般会在conf/vhosts目录下
可以针对某个项目进行限制IP访问
限制单个或者多个ip访问
<VirtualHost *:80>
DocumentRoot "D:/project/AAA.com"
ServerName api.com
ServerAlias
FcgidInitialEnv PHPRC "D:/phpstudy_pro/Extensions/php/php7.3.4nts"
AddHandler fcgid-script .php
FcgidWrapper "D:/phpstudy_pro/Extensions/php/php7.3.4nts/php-cgi.exe" .php
<Directory "D:/project/api.any1door.com">
Options FollowSymLinks ExecCGI
AllowOverride All
Order allow,deny
#默认是允许所有IP访问
Allow from all
#新增限制的访问的IP,多个IP就新增多行
Deny From 192.168.1.1/24
#新增限制的访问的IP段
Deny From 192.168.1.100
#新增允许访问的IP,多个IP就新增多行
Allow From 192.168.0.101
#新增允许的访问的IP
Allow From 192.168.1.1/24
#也可以通过文件的形式来,创建目录跟httpd.conf所在目录一致
include conf/ip.conf #include引入,
Require all granted
DirectoryIndex index.php index.html error/index.html
</Directory>
</VirtualHost>
ip.conf写法跟上面写法一致
Deny From 192.168.1.1/24
#新增限制的访问的IP段
Deny From 192.168.1.100
#新增允许访问的IP,多个IP就新增多行
Allow From 192.168.0.101
#新增允许的访问的IP
Allow From 192.168.1.1/24
修改完配置文件,重启apache
网友评论