Apache:限制对虚拟主机内特定源IP的访问

标签 apache apache2

我在同一个 apache 服务器上有多个命名虚拟主机,对于其中一个虚拟主机,我需要确保只允许访问一组特定的 IP 地址。

请建议执行此操作的最佳方法。我已经查看了 mod_authz_hosts 模块,但看起来我无法在虚拟主机内执行此操作。

最佳答案

对于 Apache 2.4,您可以使用 Require IP directive 。因此,仅允许来自 192.168.0.0/24 网络的计算机(范围 192.168.0.0 - 192.168.0.255)

<VirtualHost *:80>
    <Location />
      Require ip 192.168.0.0/24
    </Location>
    ...
</VirtualHost>

如果您只想让本地主机能够访问,那么有一个特殊的 Require local directive .

The local provider allows access to the server if any of the following conditions is true:

  • the client address matches 127.0.0.0/8
  • the client address is ::1
  • both the client and the server address of the connection are the same

This allows a convenient way to match connections that originate from the local host:

<VirtualHost *:80>
    <Location />
      Require local
    </Location>
    ...
</VirtualHost>

关于Apache:限制对虚拟主机内特定源IP的访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19711716/

相关文章:

apache - 如何使用 Linux 对 Web 服务器进行基准测试/负载测试

apache - 如何为 Apache 使用自动主机?

Python + Django 在 apache2 (httpd)、Redhat 上的不同用户下运行

apache - sudo : pecl7. 2-sp:找不到命令

Apache2反向代理首次安装永远加载

c - 尝试在 Apache [Cloud9IDE] 上打开文件时在 header 之前结束脚本输出

apache - 重写 URL 以匹配 Locationmatch

apache - Apache VirtualHost缓慢查找

node.js - Apache、NodeJs、服务器发送事件

amazon-ec2 - Apache2 服务器和 Superset,502 代理错误,加载仪表板时从远程服务器读取错误