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

Virtual host configuration for Apache Internet
From the editor: Would you like the ability to easily access web sites you set up by name, instead of by number? If so, you'll want to use Virtual Hosts in Apache which will let you do just that. Read the rest of the article for jaccorens' instructions on how to configure it. I have not done this yet on my machine, but intend to ... someday when I get some free time!

Here's how to add some named localhosts to your OS X setup:
  1. open the NetinfoManager and become admin under the domain menu > security > authenticate.

  2. duplicate the localhost entry under the machines entry

  3. rename this copy to your prefered sitename (, I used ".dev" because it's not used on the internet!

  4. open your and SU to root

  5. type 'open -e /private/etc/httpd/httpd.conf' (without the quotes)

  6. find "#NameVirtualHost" in httpd.conf file

  7. change this into: "NameVirtualHost *" (remove the # and add the *, don't type the quotes)

  8. at the end of the file, make an entry like this:
    <VirtualHost *>
    DocumentRoot /Library/WebServer/
  9. in your /Library/WebServer/ folder, make an folder named like above (

  10. want more virtual hosts? do step 2 & 3 (, enz..)

  11. repeat step 8 & 9

    works here, questions.. feel free :-)
  • Currently 2.63 / 5
  You rated: 4 / 5 (8 votes cast)

Virtual host configuration for Apache | 11 comments | Create New Account
Click here to return to the 'Virtual host configuration for Apache' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
DNS Entry?
Authored by: Gwyrrdin on Apr 24, '01 04:00:15AM


Maybe a dumb question, but I always worked only with domainnames purchased by eq. an ISP.

What's the point of giving a local website a virtualdomain when it doesn't have a DNS entry?
Only yourself from behind your own OS X box will be able to find you?

Or am I completely wrong?

I hope so:)



[ Reply to This | # ]
It's easier!
Authored by: robg on Apr 24, '01 08:33:12AM

The names are only local (you should probably avoid using something that might be publicly usable, as you'd get odd results). However, it makes it much easier to remember what you're working on, if you have a number of sites.

Compare "127.0.01/customer1", "" to "dev.customer1.mine" and "dev.customer2.mine". easier to rememember the name instead of the number/name.


[ Reply to This | # ]
DNS Entry?
Authored by: Anonymous on Jul 30, '02 07:15:41AM

a) you can edit (ie break) your sites locally without affecting the 'live' site)

b) you can specify absolute path and they'll work

c) if you mimic your ISP's paths php includes etc will work

[ Reply to This | # ]
DNS Entry?
Authored by: timrob on Jul 31, '02 04:55:13PM

Well you can give different names to sections of your server.
If you setup an alias (CName?) in DNS that points to *.yourdomain.tld,
you can have http://foo.yourdomain.tld and http://bar.yourdomain.tld.
You can setup up as many of these Virtual Hosts as you like and refer
to them by name by using the "ServerName" directive in your
Virtual Host configuration.


NameVirtualHost *

<VirtualHost *>
DocumentRoot /path/to/site/html
ServerName foo.yourdomain.tld

<VirtualHost *>
DocumentRoot /path/to/othersite/html
ServerName bar.yourdomain.tld

You can also do this without touching NetInfo.

[ Reply to This | # ]
OK ... but
Authored by: moyashi on May 02, '01 10:40:47PM

OK, I was hoping that this setup would allow me to work on development sites without actually dialling up to the net ...

So how do :

call this from my browser; ie iCab ..... or http://localhost/
My browser likes to hang since it can't find the correct location.

and, is this ok? /Library/Webserver/

in Netinfo Manager I have:
serves ./local

Which brings me to another question I've been tying to figure out. I want to organize the WebServer directory so that I can work on my friends site and my own. This is all no-cash (free beer and dinner funding from my friend) work that I do for my friend but I also would like to have my own site cleanly setup, will the above HINT workf for me?

and while I'm here. I would like to imitate my hosted IP site setup:
tye of format.

Any clues on this?

I'm sure a lot of dialup users could benefit from having a similar setup on their desktop as their IP.


[ Reply to This | # ]
Answer for ya :)
Authored by: DracoNB on Jan 03, '02 08:59:28PM

Yes you can emulate how your ISP does their setup! :) I just did it with mine :)

just change this:

# Keep this first one to enable localhost/ to still function

DocumentRoot /Library/WebServer/Documents
ServerName localhost

# Edit this to fit your needs :)
DocumentRoot /path/you/want/to/use


[ Reply to This | # ]
Answer for ya :)
Authored by: moyashi on Sep 02, '02 12:03:21PM

Whoo, missed this thread some how.

Thanks for the reply and sorry for the realllllly late thanks


[ Reply to This | # ]
Global/local httpd.conf
Authored by: Anonymous on Jul 30, '02 08:33:27AM

Any reason not to put the <VirtualHost *> block in the user's own .conf file in /private/etc/httpd/users? Keeps your stuff separate from the 'main' stuff.

Also, don't forget to restart Apache from the Terminal when you're finished editing httpd.conf for your changes to take effect: sudo apachectl restart

[ Reply to This | # ]
Global/local httpd.conf
Authored by: bluehz on Jul 30, '02 08:54:39AM

I have all my virtual hosts in seperate files and it works great - I find it much easier to open the specific file for each domain rather than the main httpd.conf file. Use an include statement in the main httpd.conf to include as many seperate files as desired:

Include /path/to/vhost.conf

[ Reply to This | # ]
Without NetInfo?
Authored by: springstdigital on Jul 31, '02 11:47:00PM

It took me a while, but I finally got this kind of set up to work (and it works great!), but until I actually involved the NetInfo Mangager it didn't work. I had to create additional 'machine' entries as described in the original post of this thread. How could it be done without NetInfo? (just curious)

[ Reply to This | # ]
Virtual host configuration for Apache
Authored by: Anonymous on Mar 13, '03 03:07:49PM

Under Mac OS X 10.2 (a.k.a. Jaguar)

step 1 edit your `/etc/hosts` file like this:

# Host Database
# Note that this file is consulted when the system is running in single-user
# mode. At other times this information is handled by lookupd. By default,
# lookupd gets information from NetInfo, so this file will not be consulted
# unless you have changed lookupd's configuration.
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
## localhost broadcasthost
::1 localhost www.yoursite1.test www.yoursite2.test

step 2 edit your `/etc/httpd/httpd.conf` file like this:
at the end of the file;

# Use name-based virtual hosting.
NameVirtualHost *

# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#<VirtualHost *>
# ServerAdmin
# DocumentRoot /www/docs/
# ServerName
# ErrorLog logs/
# CustomLog logs/ common
<VirtualHost *>
DocumentRoot /Library/WebServer/Documents/www.yoursite1.test
ServerName www.yoursite1.test
<VirtualHost *>
DocumentRoot /Library/WebServer/Documents/www.yoursite2.test
ServerName www.yoursite2.test

Now reboot your apache, and it should be all good!

[ Reply to This | # ]