Apache - 限制 IP 不起作用

发布于 2024-08-30 05:23:01 字数 508 浏览 8 评论 0原文

我有一个子域,我只想在内部访问;我试图通过编辑该域的 VirtualHost 块来在 Apache 中实现此目的。有人能看出我哪里出错了吗?注意,我这里的内部IP地址是192.168.10.xxx。我的代码如下:

<VirtualHost *:80>
  ServerName test.example.co.uk
  DocumentRoot /var/www/test
  ErrorLog /var/log/apache2/error_test_co_uk.log
  LogLevel warn
  CustomLog /var/log/apache2/access_test_co_uk.log combined
  <Directory /var/www/test>
    Order allow,deny
    Allow from 192.168.10.0/24
    Allow from 127
  </Directory>
</VirtualHost>

谢谢

I've a subdomain that I only want to be accessible internally; I'm trying to achieve this in Apache by editing the VirtualHost block for that domain. Can anybody see where I'm going wrong? Note, my internal IP address here are 192.168.10.xxx. My code is as follows:

<VirtualHost *:80>
  ServerName test.example.co.uk
  DocumentRoot /var/www/test
  ErrorLog /var/log/apache2/error_test_co_uk.log
  LogLevel warn
  CustomLog /var/log/apache2/access_test_co_uk.log combined
  <Directory /var/www/test>
    Order allow,deny
    Allow from 192.168.10.0/24
    Allow from 127
  </Directory>
</VirtualHost>

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

甩你一脸翔 2024-09-06 05:23:01

您缺少 Deny from all 行吗?哦,还有使用了错误的顺序

引用 mod_access 文档

[...] apache.org 域中的所有主机都被允许访问;所有其他主机都被拒绝访问。

订单拒绝,允许
所有人都否认
允许来自 apache.org

You're missing the Deny from all line? Oh, and using the wrong order.

Quoting the mod_access docs:

[...] all hosts in the apache.org domain are allowed access; all other hosts are denied access.

Order Deny,Allow
Deny from all
Allow from apache.org
长梦不多时 2024-09-06 05:23:01

问题是您的本地网络允许线路。将 Allow from 192.168.10.0/24 替换为 Allow from 192.168.10.(将允许 192.168.10.*)。

为了完整起见,请添加 Deny from all 行,以明确您正在阻止其他所有人。

The problem is your allow line for the local network. Replace Allow from 192.168.10.0/24 with Allow from 192.168.10. (will allow 192.168.10.*).

For completeness, add a Deny from all line to make it clear that you're blocking everyone else.

笨死的猪 2024-09-06 05:23:01

我想 Directory 标签内的路径应该只是 /

<VirtualHost *:80>
  ServerName test.example.co.uk
  DocumentRoot /var/www/test
  ErrorLog /var/log/apache2/error_test_co_uk.log
  LogLevel warn
  CustomLog /var/log/apache2/access_test_co_uk.log combined
  <Directory />
    Order allow,deny
    Allow from 192.168.10.0/24
    Allow from 127
  </Directory>
</VirtualHost>

并且请不要忘记重新启动 apache

I suppose the path inside Directory tag should be simply /

<VirtualHost *:80>
  ServerName test.example.co.uk
  DocumentRoot /var/www/test
  ErrorLog /var/log/apache2/error_test_co_uk.log
  LogLevel warn
  CustomLog /var/log/apache2/access_test_co_uk.log combined
  <Directory />
    Order allow,deny
    Allow from 192.168.10.0/24
    Allow from 127
  </Directory>
</VirtualHost>

and please don't forgot to restart apache

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文