Make apache only accessible via 127.0.0.1, is this possible

apache-2.2httpd.confloopbackwindows 7

I've set up my Apache server, and the PHP/MySQL works well!

But the issue is, how do I keep this private, since it's a development-only server?
The only reason for keeping the content private is if a script went wrong, I don't want Apache errors showing up if it became a public-facing site (and the fact others share the same network too!), and I'm less likely to use my PC as a webhost – I'm more likely to go down using the webhosting provider route for an actual live site.

Currently I can access it three ways:

  • http://localhost (or http://127.0.0.1, the alternate way and localhost's IP but either way is acceptable with me!)

  • http 192.168.0.1 (my router's IP)

  • http pc-name-here (name of my PC, obviously this varies between Windows PCs!)

[note, can't post links, so for the other two you'd have to insert the colon/forward slash as in the first one].

However, I only want to access it via the first one. It's listening on port 80 (and I don't want to change that). Is this not possible, or am I mistaken? I know a bit more about PHP/webdesign than the network side of things, so this is a first for me!

Basically, I want it to be only accessible via localhost on that machine, and not the external IP address, or 192.168.0.1 .

Would I need to edit httpd.conf and use deny on every testbed site, or is there any other solution?

Example:

<Directory /www/vhosts/localhost/>
    Options All
    AllowOverride All
    order allow,deny
    allow from 127.0.0.1
            deny from 192.168.0.1
            deny from my-pc-name
</Directory>
  • that's an example but I'm not sure what's right or wrong here!

My operating system is Windows 7 Ultimate.

I did have a look round the 'net, but some of it seemed a bit technical for me.

What would you recommend?

Best Answer

The easiest way to do this is through the Listen directive. By defaults, there's a line in our httpd.conf that reads:

Listen *:80

Meaning it will respond ro requests on port 80 on all of your computer's network addresses. Changing it to:

Listen 127.0.0.1:80

Will tell apache only to only respond to requests on the local adaptor, thus ignoring anything else.

Related Topic