apache 仅允许 IP 本地主机返回错误 301



我只是试图只允许从本地主机访问Web服务器。这是一个全新的 CentOS 7 安装,带有 apache 2.4.6。

我创建了一个基本的网络:

[root@server2 ~]# cat /var/www/html/secret/index.html
my password
[root@server2 ~]#

然后,虚拟主机和目录作为 apache 2.4+ 的官方文档(192.168.1.10 它是服务器 IP,我在/etc/hosts192.168.1.10 serverX.example.com):

[root@server2 ~]# cat /etc/httpd/conf.d/varios.conf
<VirtualHost *:80>
    DocumentRoot /var/www/html/secret
    ServerName serverX.example.com
</VirtualHost>
<Directory "/var/www/html/secret">
    AllowOverride None
    Options None
    Require ip 127.0.0.1 192.168.1.10
</Directory>
[root@server2 ~]#

一切都应该工作,但是:

[root@server2 ~]# curl serverX.example.com/secret
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /secret
on this server.</p>
</body></html>
[root@server2 ~]#

知道吗?

要使虚拟主机仅供本地主机访问,您可以将其绑定到 IP 地址 127.0.0.1。

<VirtualHost 127.0.0.1:80>
    DocumentRoot /var/www/html/secret
    ServerName serverX.example.com
</VirtualHost>

/etc/hosts中,您可以改用127.0.0.1 serverX.example.com

有必要在末尾添加一个/

curl serverX.example.com/secret/

使用火狐工作正常,但使用卷曲或elinks,则不行。

此致敬意。

最新更新