Search code examples
wampwampserverwindows-server

wampserver homepage only visible from localhost


Recently I used WAMP server to set up a server environment in a Windows machine. Everything works great, but I have a little problem: everyone can access the wampserver homepage, therefore they can see other webpages hosted in the same server, the server file system, etc.

The URLs of the webpage have the following format: hostname/project1, hostname/project2... The main problem is that, anyone can see all the projects that are hosted by going to the direction of the hostname because this will lead to the wampserver homepage, and I would prefer that this homepage could be accessed only in the localhost of the windows host. Is there any way to do that? I'm guessing that I will need to modify some parameters in configuration files, but I have no idea wich ones...


Solution

  • If you intend to block access to all sites hosted on this computer from outside access, you can do this in your main apache configuration file at <installation drive>/wamp/bin/apache/Apache<version number>/conf/httpd.conf. .htaccess is more for per-site configurations, though it will certainly work if you put it in the main www directory.

    To disallow outside access to the www folder (open by default) find the part of the apache configuration file (path shown above) that looks like:

    <Directory "<installation drive>/wamp/www">
        # There will be comments here and some options like FollowSymLinks and AllowOverride
        Order Allow,Deny
        Allow from all
    </Directory>
    

    And change it to:

    <Directory "<installation drive>/wamp/www">
        # There will be comments here and some options like FollowSymLinks and AllowOverride
        Order Deny,Allow
        Deny from all
        Allow from 127.0.0.1
    </Directory>
    

    If your goal is not to block outside access to all of your sites, it would help to know more about your set up. And if your goal is only to block the 'localhost' page and still allow access to, say, 'localhost/site1' then this question may be a duplicate of this.

    Edit: As you point out, there is not a good resolution for the question I linked. Assuming you have your public sites set up as virtual hosts in a sub folder of the webroot like:

    |-wamp_root
      |-www
        |-vhosts
          |-public_site_1
          |-public_site_2
    

    Then you can go back into your httpd.conf and add this below your /wamp/www/ rule:

    <Directory "<installation drive>/wamp/www/vhosts/">
        # There will be comments here and some options like FollowSymLinks and AllowOverride
        Order Allow,Deny
        Allow from all
    </Directory>
    

    This will allow anything in the www folder to be accessed only locally, and anything in the vhosts sub folder to be accessible outside. Again, remember to restart Apache whenever you change this file.