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

Apache virtual host setup tips UNIX
This is a first ... asking for help on my own site! I'm trying to set up Apache to run virtual hosts, and I'm having a bit of trouble.

If you have experience in this area and can lend a hand, please read the rest of this article for the details on what I'm trying to accomplish.

[see the notes for some helpful tips]

OK, here's my setup: DSL line with one static IP (let's say it's, even though that's an internal number ... just for ease of typing), no domain name established, Linksys router serving as the firewall and router which is configured via an HTTP server running on port 80, internal network of three machines all established with 192.168.1.x IP numbers. The Mac OS X box is, the router is My ISP blocks ports under 1024 to prevent local servers on normal ports.

My objective: To host two separate sites using the one IP number and the OS X box. Site #1 is an internal development site (the dev site for osxhints, actually), hosted on port 80, and residing in the default webserver file location (/Library/WebServer/Documents). I don't want this site accessible to the outside world at all (and it won't be by default, since the ISP blocks port 80 activity). Site #2 is our family's site, accessible (via .htaccess password restrictions) to the outside world, which I'd like to run on port 8080. It's stored in /foo/bar/familysite. My router can forward the 8080 port, so that part is no problem.

What I'd like to be able to do is reach the internal site by using the default "" localhost IP, and I need to be able to view the public site on my machine as well (either with, or through the public address So the question is how to I modify apache.conf to make this work? I'm not sure what to do about "ServerName" since my box doesn't have one. Here's what I tried in apache.conf:

I left as is, including the "Port 80", "ServerRoot /Library/WebServer/Documents", and "ServerName myxmachine" (the name of my OS X box, internally) lines.

I tried the following:
Listen 80
Listen 8080
DocumentRoot /foo/bar/familysite
I'm sure I'm doing something wrong; I couldn't make this work in any of the methods I tried (I tried using 127. addresses, I tried listening on IP:portnum, etc).

Can anyone walk me through what I might be missing?

  • Currently 2.20 / 5
  You rated: 3 / 5 (5 votes cast)

Apache virtual host setup tips | 10 comments | Create New Account
Click here to return to the 'Apache virtual host setup tips' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Apache virtual host setup
Authored by: robh on Feb 09, '01 01:37:55PM

Try using hostnames rather than IP numbers. Numbers are messy.

First setup some alias hostnames using NetInfoManager (append new aliases to your machine's name under the 'machines' entry). Do a restart (under the 'Options' menu) to make the new names take. This is equivalent to adding hostname aliases in /etc/hosts on other flavours of unix.

Next add these to your apache.conf ...

Listen 80
Listen 8080

<VirtualHost mymachine:80>
ServerName mymachine
DocumentRoot /Users/robg/wherever/

DocumentRoot /Users/robg/elsewhere/

If that doesn't do the trick, post (or email if you prefer) me some diagnostic info. I used to administer and had dozens of name based virtual hosts working there. I'm a little rusty right now though.

[ Reply to This | # ]
Apache virtual host setup
Authored by: Anonymous on Mar 13, '01 05:40:47PM

I am simply having trouble getting virtual hosts to work at all! I configured the apache.conf file as such:

port 80
DocumentRoot /Local/Library/WebServer/Documents/dir1
ServerName domainname_of_computer

<VirtualHost second_ip>
DocumentRoot /Local/Library/WebServer/Documents/dir2
ServerName domainname_of_second_ip

I did not set the Listen or BindAddress directives to anything. At this point, I can access the main domain but not the virtual one. Is there something else that I need to do to make this work? Is there something at the system level? Someone please help!


[ Reply to This | # ]
Apache virtual host setup
Authored by: robh on Mar 14, '01 01:57:41PM

Try the suggestions in my previous post. Avoid numeric IPs in the config.

[ Reply to This | # ]
Apache virtual host setup
Authored by: Anonymous on Apr 02, '01 01:45:36PM

how *exactly* do i use netInfo manager to create those other host names?

please, and thank you.

[ Reply to This | # ]
that is...
Authored by: Anonymous on Apr 02, '01 01:49:54PM

Authored by: robh on Fri, Feb 9 at 01:37PM
Try using hostnames rather than IP numbers. Numbers are messy.

First setup some alias hostnames using NetInfoManager (append new aliases to your machine's name under the 'machines' entry). Do a restart (under the 'Options' menu) to make the new names take. This is equivalent to adding hostname aliases in /etc/hosts on other flavours of unix.
how *exactly (what exactly do i do) to get NetInfo Manager to do that?

[ Reply to This | # ]
adding new hostnames
Authored by: robh on Apr 03, '01 08:51:27AM

Go to the "machines" section, find (and select) your machine's name in the list (I think it should already be there).

You'll see something like this in the bottom window:

name mymachine

Click on 'name' then using the menu at the top of the screen select:
Directory->Append Value

then type in the new alias for your machine.

Repeat the above for every alias you add.

NOTE: adding these aliases will not make these hostname aliases useable by other machines on your network or the outside Internet. These are local aliases. If you want them to be visible to other machines then you need to put them into a nameserver for your domain, and if you're making up new domain names, e.g., then you have to register (buy) the domain first.

Local aliases might seem useless given the above, but they can be VERY useful for prototyping websites that use virtual hosts.

[ Reply to This | # ]
Apache virtual host setup
Authored by: Anonymous on Apr 04, '01 08:36:00PM

I'm doing virtual hosting on MacOS X by specifying domain names rather than
portmapping. (I forget what this is called.) It works with all but the most
ancient browsers, and is easier and cleaner because you can have n sites
all hosted from port 80, which makes router configuration easier too. (I'm
also doing this from inside a LinkSys firewall/router.) My ISP doesn't
block port 80 (man, you need a new isp!) so I don't have to play around
with ports like you have to.

Here's what my /etc/httpd/httpd.conf file looks like in the relevant
section. Say is the server's address on the network inside the

DocumentRoot "/Library/Webserver/Documents/mydomain"

DocumentRoot "/Library/Webserver/Documents/myotherdomain"

DNS for these domains is being served by (Zoneedit
kicks butt, at least as far as I can tell after two weeks.)

I can't really see how different the above is from your setup. One thing to
remember is that Linksys routers don't do forwarding on packets coming from
inside the firewall. So you might actually have everything configured right
and working for everyone in the world except you. That's what I found.

Since I'm inside the firewall, requests for my domains return "my" (really
my router's at this point) static IP address, just like they do for
everyone else. The problem is sending http requests to the router from
*inside* pulls up the linksys config page instead of having the packets
forwarded to the MacOS X machine on the local network. (SSH out to some
other host and lynx your way back in to see if things look ok from the

I can fix this under OS 8.6 by editing the MacOS Hosts file like this: A A

...but I can't get this to work under OS X! Like others, I've seen that
/etc/hosts tells you to use NetInfo, and I've been trying to use NetInfo
following the suggestions posted in this thread. So far, no luck.

The fact that NetInfo has zero documentation is really annoying. (There's
some old NeXT stuff at Apple, such as

but this hardly counts.)

-Rob Calhoun

[ Reply to This | # ]
Questions about this Hint: Apache virtual host setup.
Authored by: spoon on Aug 25, '02 04:30:30AM

"DNS for these domains is being served by"

How do you have zoneedit set up?
Pointing to the router's IP, I guess? How does the router point it to the machine, or must the machine have a "real" IP, not an intranet IP?

Could you please explain this point a bit further? I'm trying to configure a Mac OS X 10.2 (not server) machine, with a web server (hosting many domains, with one IP) and also share the DSL modem with the rest of the office (seems like Jaguar has this new feature built in).

Is this even possible with only one Ethernet card and a 2MB DSL modem with a static IP?

I'm not doing the DNS. I use a zoneedit-like service that points DNS to my server's IP -- all the domains to the same IP. I'm planning to host 4 or 5 domains (small sites) on the same machine.


[ Reply to This | # ]
Apache virtual host setup tips
Authored by: logo on Mar 12, '03 07:28:22AM

Now: did anyone get this working? robg?

I'm facing the same problem now (6months after you all!)

my setup: for the plain webserver in OS X

tomcat.ibook.local which resolves also to should go directly to /Library/Tomcat/webapps/examples

Any clues?

Thanks in advance!

[ Reply to This | # ]
Apache virtual host setup tips
Authored by: bluehz on Mar 13, '03 12:49:16AM

I had a lot of trouble with localhost also - because I run my own dns server for our internal LAN. Whenever I issued a call to a localhost address the DNS was being searched first and it was abviously not finding anything. There is a way to do this in NetInfo Manager by adjusting the order that lookupd searches. Although I have never had much luck with that either. I finally found a simple solution last week that so far has been working.

Open System Preferences > Network > TCP/IP and enter "localhost" as the top name in the "Search Domains" field. You may have other names there already - but put localhost at the top of the list. This seems to cause a search of your machine before going elsewhere.

Hope that helps.

[ Reply to This | # ]