美文网首页PHP程序员
apache 限制IP访问

apache 限制IP访问

作者: php转go | 来源:发表于2020-08-20 11:03 被阅读0次

找到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

相关文章

网友评论

    本文标题:apache 限制IP访问

    本文链接:https://www.haomeiwen.com/subject/poudjktx.html