0

I have a small windows server set up on a LAN, with static IP address 192.168.1.100. I have a few other client machines, say 192.168.1.101 - 104.

Requirements:

  • Host an apache server (wampserver) on the main server, accessible only on the LAN.
  • Set up the default wampserver tools (such as phpmyadmin) on port 8080, accessible only from the server machine
  • Use port 8081 for a special internal site, accessible by all machines on the LAN

My current setup as follows:

httpd.conf:

ServerRoot "c:/wamp/bin/apache/apache2.2.22"

Listen 8080
Listen 8081

ServerAdmin admin@localhost
ServerName localhost:8080
DocumentRoot "c:/wamp/www/"

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

<Directory "c:/wamp/www">
    Options Indexes FollowSymLinks
    AllowOverride all
     Order deny,allow
     Deny from all
     Allow from 192.168.1
</Directory>

<Directory "c:/site1">
    Options Indexes FollowSymLinks
    AllowOverride None
     Order deny,allow
     Deny from all
     Allow from 192.168.1
</Directory>

<Directory "cgi-bin">
    AllowOverride None
    Options None
     Order deny,allow
     Deny from all
     Allow from 192.168.1
</Directory>

httpd-vhosts.conf:

Listen 8080
Listen 8081

NameVirtualHost *:8080
NameVirtualHost *:8081

<VirtualHost *:8080>
    ServerName localhost
    DocumentRoot c:/wamp/www
</VirtualHost>

<VirtualHost *:8081>
    ServerName site1
    DocumentRoot c:/site1
</VirtualHost>
  • I have opened up port 8081 on the windows server
  • I have added "site1" to point to 192.168.1.100 on the hosts files of the client machines
  • I have added an alias on the server

    Alias /site1/ "c:/site1/"

    Options Indexes FollowSymLinks MultiViews AllowOverride all Order allow,deny Allow from all

The problem now is that the behaviour is not quite what I need.

Current behaviour on the server:

  • 192.168.1.100:8080 serves me c:/wamp/www as expected
  • 192.168.1.100:8081 also serves me c:/wamp/www instead of c:/site1 that I expect
  • instead, 192.168.1.100:8081/site1 serves me c:/site1

Current behaviour on client machines:

  • site1:8081 (or 192.168.1.100:8081) serves me the c:/wamp/www on the server, instead of c:/site1 that I expect. I don't want c:/wamp/www accessible from clients.
  • instead, site1:8081/site1 (or 192.168.1.100:8081/site1) serves me the c:/site1 on the server.

What am I doing wrong?

6
  • 1
    This is a development tool. Trying to serve real, live sites on it is the first wrong. Mar 22, 2013 at 4:04
  • I don't understand your comment. What's wrong with serving a site internally to my organization? Mar 22, 2013 at 4:10
  • He means WAMP. WAMP is meant for easy dev deployments, not serving real sites. (Not saying I agree 100%, but that's what he meant and from what I've seen from previous versions he's probably right).
    – gparent
    Mar 22, 2013 at 4:15
  • 1
    Like other development tools of its type, it is not designed or intended to be used in production. Which includes "serving a site internally to my organization". Mar 22, 2013 at 4:15
  • I have limited server knowledge and I just need a quick and simple setup for a simple site (eg a wiki) for a few client users on the LAN only. Is WAMP too limited to work in this scenario? If so what should I be using? Mar 22, 2013 at 4:20

2 Answers 2

2
+50

Maybe an explanation on how name base virtual hosts work is helpfull here.

When a browser sends a request for 192.168.1.100:8081 what it does is connecting to 192.168.1.100. port 8081 and subsequently it will send a http request. This looks (simplified) a bit like this:

host: 192.168.1.100

GET /

Apache now needs to find out from which virtual host it will service the response. It does this by looking at the IP:Port pair, and if a NamevirtualHost statement exists for the IP:Port pair it also looks at the host: header. The important thing to be aware of here is that if you call up a site by IP, the host:header will contain the IP address, not the name of the host. You need to use names (and they need to correctly resolve to the correct ip).

If Apache can't find a virtualhost that matches the IP:Port:Host combination it defaults to the first VirtualHost section. And this is what is happening here. Just swap your two sections around and see what happens...

What you need to stop doing here is confusing apache by mixing named based virtualhosts and port based virtualhosts. In other words, you need to remove the NameVirtualHostdirectives. You don't need them.

One last remark: If the aim is to block everyone but the server itself on the wamp directory you need to change something else on your config too:

<Directory "c:/wamp/www">
    Options Indexes FollowSymLinks
    AllowOverride all
    Order deny,allow
    Deny from all
    Allow from 192.168.1.100
</Directory>

This way only the server gets to see this dir...

2

I think the problem is with your name based virtual hosting. You've told it via the ServerName directive that its hostname is "site1", whereas in fact they are both localhost. Don't use name based virtual hosting, just allow it to choose from the port.

Remove all the NameVirtualHost and ServerName lines from the httpd-vhosts.conf.

3
  • Hi can you elaborate why "in fact they are both localhost"? Thanks, Mar 24, 2013 at 12:27
  • 1
    Your rule to serve C:\site1 would only trigger if you are accessing that port and addressing the server as 'site1'. You're addressing it as '192.168.1.100'.
    – crb
    Mar 26, 2013 at 17:25
  • 1
    Yes to expand a little on what crb said, when you go to site1 you're going to 192.168.1.100:8081 not site1:8081, so you can't use name-based virtual hosting and tell it to look for the name (domain) "site1", because it never sees "site1", only the IP address. Mar 26, 2013 at 20:38

Not the answer you're looking for? Browse other questions tagged .