ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Apache Web-Serving with Mac OS X, Part 6
Subject:   How to setup virtual hosts
Date:   2002-10-10 22:24:36
From:   kiddailey
Response to: what about Virtual Hosts?

Tatlar:


I grew impatient and figured out a way to do this myself -- it was extremely easier than I thought it would be. Standard disclaimer applies: it worked for me, but I take no responsibility :)


Step 1:
-------


Load up your http.conf file (/etc/httpd/httpd.conf) in your favorite text editor, and uncomment the following lines by removing the pound sign (#):


#LoadModule vhost_alias_module libexec/httpd/mod_vhost_alias.so


#AddModule mod_vhost_alias.c



Step 2:
-------


Search for the following line:


UseCanonicalName On


... and turn it off by changing it to:


UseCanonicalName Off



Step 3:
-------
Add the following line right below the last one you modified in step 2:


VirtualDocumentRoot /Library/WebServer/Documents/%0


Basically this says reroute to the folder that matches the server name. i.e. http://www.foo.com -> /Library/WebServer/Documents/www.foo.com/ In theory, you could use any folder, but I chose to simply repurpose my webserver documents directory.



Step 4:
-------
Save the file and restart your web server (turn web sharing off and then on again).



Now the trick to getting this to work completely is to simply create folders for each domain name you want to host virtually. For example, say you have two sites: www.foo.com and www.bar.com. In your webserver documents folder, you'd simply create folders with the same names:


/Library/WebServer/Documents/www.foo.com
/Library/WebServer/Documents/www.bar.com


And put the files for each site in the respective folders.


Magic!


Note that you might need to tweak this to get www.foo.com and foo.com to point to the same place (using aliasing, I'd imagine). You can read all about the vhost_alias module and VirtualDocumentRoot directive at http://httpd.apache.org/docs/mod/mod_vhost_alias.html


1 to 1 of 1
  1. How to setup virtual hosts
    2007-03-08 11:23:01  jepler@hotmail.com [View]

1 to 1 of 1