skip to Main Content

I’m trying just to allow access to a web server from the localhost only. This is a fresh CentOS 7 installation with apache 2.4.6.

I created a basic web:

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

Then, the virtualhost and directory as official documentation for apache 2.4+ (192.168.1.10 it’s the server IP and I have 192.168.1.10 serverX.example.com in the /etc/hosts):

[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 ~]#

Everything should work, but:

[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 ~]#

Any idea?

2

Answers


  1. Chosen as BEST ANSWER

    It was necesary to add one / at the end:

    curl serverX.example.com/secret/
    

    With firefox works fine, but with curl or elinks, no.

    Best regards.


  2. To make the virtual host accessible to localhost only, you can bind it to the ip address 127.0.0.1.

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

    In /etc/hosts you can use 127.0.0.1 serverX.example.com instead.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search