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 10.0.0.1, 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 192.168.1.100, the router is 192.168.1.1. 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 "127.0.0.1/" localhost IP, and I need to be able to view the public site on my machine as well (either with 127.0.0.1:8080, or through the public address 10.0.0.1:8080). 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:

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

VIRTUAL HOST SECTION:
I tried the following:
Listen 80
Listen 8080
<VirtualHost 10.0.0.1:8080>
DocumentRoot /foo/bar/familysite
</VirtualHost>
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?

-rob.
    •    
  • Currently 2.20 / 5
  You rated: 3 / 5 (5 votes cast)
 
[14,069 views]  

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/
</VirtualHost>

<VirtualHost family.isp.com:8080>
ServerName family.isp.com
DocumentRoot /Users/robg/elsewhere/
</VirtualHost>

If that doesn't do the trick, post (or email if you prefer) me some diagnostic info. I used to administer imdb.com 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
</VirtualHost>

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!

Thanks,
Jason



[ 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?
thanks.
ichi



[ 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:

ip_address 1.2.3.4
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. www.mynewdomain.com, 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 192.168.1.90 is the server's address on the network inside the
firewall.

<VirtualHost 192.168.1.90>
ServerName www.mydomain.com
DocumentRoot "/Library/Webserver/Documents/mydomain"
</VirtualHost>

<VirtualHost 192.168.1.90>
ServerName www.myotherdomain.com
DocumentRoot "/Library/Webserver/Documents/myotherdomain"
</VirtualHost>

DNS for these domains is being served by zoneedit.com. (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
outside.)

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

www.mydomain.com A 192.168.1.90
www.myotherdomain.com A 192.168.1.90

...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

http://www.enterprise.apple.com/NeXTanswers/HTMLFiles/1060.htmld/1060.html

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 zoneedit.com."

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.

(help!)etc://Lp



[ 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:

127.0.0.1 for the plain webserver in OS X

tomcat.ibook.local which resolves also to 127.0.0.1 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 | # ]