Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.7: Virtual Hosts and multiple web servers OS X Server
After a great deal of searching the net for answers I have pieced together what is needed to do a couple of things I have wanted to do for some time now. The first is to have virtual hosts working nicely on 10.7 Lion Server. The second and related item is to have multiple web servers within a LAN accessible from one WAN address.

Virtual Hosts

To get this working add the following line to the /etc/apache2/httpd.conf file and then restart the web service.

NameVirtualHost *:80

Restarting the web service can be done in the Terminal using:

sudo serveradmin stop web
sudo serveradmin start web


Now you can add virtual hosts through the Server app.

Multiple web servers within a LAN accessed from one WAN address.

Set up: The following assumes that you have 3 servers with correctly working DNS and apache services. The 10.10.10.x subnet is used for the examples, change them to whatever configuration you are using.

Set up a NAT rule on your router/modem to point port 80 through to, for example, 10.10.10.200 (or the address of the primary apache service that will redirect domains to their correct machine):
  • first.domain.com = 10.10.10.200
  • second.domain.com = 10.10.10.201
  • third.domain.com = 10.10.10.202
DNS on the primary machine should be set up as follows:
  • ZONE - domain.com
  • machine record server1.domain.com. points to 10.10.10.200
  • machine record server2.domain.com. points to 10.10.10.201
  • machine record server3.domain.com. points to 10.10.10.202
  • alias record first.domain.com. points to server1.domain.com.
  • alias record second.domain.com. points to server2.domain.com.
  • alias record third.domain.com point to server2.domain.com.
External DNS needs to be set up that points first.domain.com, second.domain.com and third.domain.com to your external IP address where your web server is located such as 210.55.102.xx (remember this can take up to 48 hours to become live).

Once this is done you can start adding the .conf files to the /etc/apache2/sites folder to do the redirecting.

You can name the files as you like so long as they have the .conf extension.

1st File I will call 0000_any_80_first.domain.com.conf it needs the following in it to do the redirect to the correct machine:
<VirtualHost *:80>
ServerName first.domain.com
ProxyPreserveHost on
ProxyPass / http://server1.domain.com/
ProxyPassReverse / http://server1.domain.com/
</VirtualHost>
2nd File is called 0000_any_80_second.domain.com.conf containing:
<VirtualHost *:80>
ServerName second.domain.com
ProxyPreserveHost on
ProxyPass / http://server2.domain.com/
ProxyPassReverse / http://server2.domain.com/
</VirtualHost>
3rd File is called 0000_any_80_third.domain.com.conf containing:
<VirtualHost *:80>
ServerName third.domain.com
ProxyPreserveHost on
ProxyPass / http://server3.domain.com/
ProxyPassReverse / http://server3.domain.com/
</VirtualHost>
Restart the web service with the Terminal command:

sudo serveradmin stop web
sudo serveradmin start web


[crarko adds: I haven't tested this one. This might also be possible to do in Lion client, but the hint as is applies to Lion Server.]
    •    
  • Currently 3.80 / 5
  You rated: 4 / 5 (10 votes cast)
 
[17,252 views]  

10.7: Virtual Hosts and multiple web servers | 7 comments | Create New Account
Click here to return to the '10.7: Virtual Hosts and multiple web servers' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.7: Virtual Hosts and multiple web servers
Authored by: alittleknowledge on Oct 13, '11 11:08:42AM

You can also go to line 623 and uncomment the line saying [code]Include /private/etc/apache2/extra/http-vhosts.conf[/code]

There are a few extra configuration options you can get just by uncommenting those lines in httpd.conf.



[ Reply to This | # ]
10.7: Virtual Hosts and multiple web servers
Authored by: swarten on Oct 16, '11 09:57:25PM

brilliant - thanks.

---
4thru2.com - IT Consultancy



[ Reply to This | # ]
10.7: Virtual Hosts and multiple web servers
Authored by: hexghost on Oct 13, '11 02:29:42PM

This isn't really an OS X hint but instead an apache hint, and should work on any OS X version's apache.



[ Reply to This | # ]
10.7: Virtual Hosts and multiple web servers
Authored by: swarten on Oct 16, '11 09:56:19PM

Actually it is a hint for OS X, Apache running on OS X.

---
4thru2.com - IT Consultancy



[ Reply to This | # ]
10.7: Virtual Hosts and multiple web servers
Authored by: leamanc on Oct 13, '11 06:02:56PM
...your external IP address where your web server is located such as 210.55.102.xx (remember this can take up to 48 hours to become live).

Actually, this is controlled by the TTL (time to live) setting on the DNS server that your domain registrar uses. I have dealt with registrars that have had TTL set to something ridiculously high like two weeks! Another one had it set to 60 seconds, which is ridiculously low.

While 48 hours seems to be a common standard, I just thought I'd point out that DNS propagation can take a shorter or longer amount of time than that. Consult your registrar to get a better idea. Of course, client machines can ignore the TTL value (especially if you flush your DNS cache) and go get the new IP regardless. Or refuse to. :-)



[ Reply to This | # ]
10.7: Virtual Hosts and multiple web servers
Authored by: daz3210 on Jan 16, '12 07:26:02AM

Can you clarify for a newbie.

Am I right in thinking that for the websites to be visible to the outside world I forward port 80 on the router to server 1 for the multiple servers scenario?

Sorry if this sounds a silly question.




[ Reply to This | # ]
10.7: Virtual Hosts and multiple web servers
Authored by: swarten on Feb 05, '12 02:53:55AM

Not a silly question at all.

Yes, that is correct. The router points port 80 to server 1 which has the apache config set to redirect requests to other servers.

---
4thru2.com - IT Consultancy



[ Reply to This | # ]