23

我已经看遍了,但不断遇到关于目录级别 IP 限制的相同信息,通常看起来像这样:

Order Deny,Allow
Deny from all
Allow from 123.123.123.123

是否可以将相同类型的访问限制绑定到页面/文档?

4

4 回答 4

37

这将允许来自 IP 127.0.0.1 的人作为有效用户登录。将其粘贴在您的配置或 .htaccess 文件中。

    <Files learn.php>
        Satisfy any
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1

        AuthType Basic
        AuthName "private"
        AuthUserFile /var/www/phpexperts.pro/.htpasswd
        AuthGroupFile /dev/null
        Require valid-user
    </Files>

仅IP:

    <Files learn.php>
        Order deny,allow
        Deny from all
        Allow from 127.0.0.1
    </Files>

这绝对回答了你的问题。

于 2010-08-30T22:08:48.653 回答
9

我认为该指令需要是:

Order deny,allow

为了使上述答案起作用(至少对于 IP Alone 解决方案)。

于 2012-05-03T12:32:39.657 回答
1

基于 Mod 重写的解决方案:

RewriteEngine on

RewriteCond %{REMOTE_ADDR} !^Y\.O\.U\.R\.IP$
RewriteRule ^file\.php$ - [F,L]

如果客户端 ip 与 RewriteCond 模式中的 ip 地址不匹配,上面的 rewriteRule 将拒绝所有对file.php的请求

于 2016-06-21T15:28:45.683 回答
1

有关更新的 Apache 2.4 示例:

<Files file.html>
    Require ip 123.123.123.123
</Files>

以下是有关其他选项和示例的更深入的文档:https<Files> ://httpd.apache.org/docs/2.4/howto/access.html 和指令的文档: https ://httpd.apache.org/docs /2.4/mod/core.html#files

请注意,<Files>可以嵌套在<Directory>部分内以限制它们适用的文件系统部分。

于 2019-09-12T21:59:24.907 回答