PDA

View Full Version : Staging server on local machine - can't get name-based virtual hosts working




Rower_CPU
Nov 17, 2004, 12:29 PM
OK, hopefully someone here has some experience with this and can let me know what's going wrong with my setup.

I'm trying to set up a couple of virtual hosts with Apache on my PowerBook for work. I've found how-to's at a couple of places, but nothing has worked so far.

- SitePoint - Configuring OS X for Web Development (http://www.sitepoint.com/article/os-x-web-development)
- evolt - Enabling Virtual Hosts on MacOS X (http://www.evolt.org/MacOSX_vhosts/)

I'm pretty sure my httpd.conf is fine, but damned if I can get /etc/hosts of NetInfo to allow me to type http://mysitename and get to my local sites.

I'll post config file contents in a minute...



kgarner
Nov 17, 2004, 12:37 PM
Try this one. Link (http://mezzoblue.com/archives/2004/08/05/virtual_host/#000642) It should work okay.

Rower_CPU
Nov 17, 2004, 01:10 PM
He's pointing to the same evolt article I linked above at the end of that post...still no go.

Here's my httpd.conf section on virtual hosts:
NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
DocumentRoot /Library/WebServer/Documents
ServerName localhost
</VirtualHost>

<VirtualHost 127.0.0.1>
DocumentRoot /Volumes/myservername
ServerName myservername
</VirtualHost>

maxvamp
Nov 17, 2004, 02:44 PM
I'm pretty sure my httpd.conf is fine, but damned if I can get /etc/hosts of NetInfo to allow me to type http://mysitename and get to my local sites.


Do you have a DNS setup at all? Also, where are you trying to call mysite from ( local machine, or from another machine ).

Max.

Rower_CPU
Nov 17, 2004, 02:49 PM
DNS shouldn't factor into this since it's using the local hosts info. Take a look at the Apache config info - I'm trying to reach a local volume.

maxvamp
Nov 17, 2004, 03:21 PM
I guess I should look a little deeper <grin>

Ok, so we know that you have a localhost of the standard 127.0.0.1, and that you have told apache to use virtual names when the browser looks up a name.

Now, when the browser tries to resolve http://mysitename to an IP, does the entry exist /etc/host that redirects the name to localhost? can you ping mysitename?

Would it be possible to post your /etc/host.

BTW: just for clarification, I would like to diagram what I know of this process. I do not mean to insult anyone's knowledge, but I would like to make sure we are on the same page :

Browser -> call site by name - > resolve site name to IP -> contact apache by IP -> Apache looks up name calling it -> depending on name, redirects files from specified site.

I am pretty certain this is the way things work here. Please correct me if I am wrong, as it have been a couple of years since I did this type of work on Apache.

Max.

jeremy.king
Nov 17, 2004, 04:36 PM
Try this

Your apache conf

NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /Library/WebServer/Documents
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /Volumes/myservername
ServerName myservername
</VirtualHost>


and your host file


127.0.0.1 localhost myservername


Im curious what IP your apache is listening on, won't matter if you use a wildcard in your apache conf file.

Good Luck!

Rower_CPU
Nov 17, 2004, 04:48 PM
max-
I can ping the sitename ("LARC" in this instance). Here's my hosts file, using kingjr's format:
127.0.0.1 localhost
255.255.255.255 broadcast
::1 localhost
127.0.0.1 localhost LARC

kingjr-
It's listening on 127.0.0.1 - just the loopback address. I'm going to be traveling so there's no point in setting a particular IP.

Trying with your "*:80" format it's still not working. Based on me being able to ping the virtual name, I think we're narrowing it down to Apache not handling it correctly...hmmm.

I've been restarting Apache after any change to the config file, but none of the tutorials say anything about resetting anything for the host file changes to take place. Is it not necessary? I've rebooted a couple time to see if it did anything, but no dice.

Thanks for the help thus far, folks - it's rare for me to get hung up on something, especially when the tutorials make it seem so straightforward.

jeremy.king
Nov 17, 2004, 05:29 PM
It must be related to your hosts file. Guess its just not as easy as Linux :eek:

Anyways, I found this article. Seems to talk about how Panther uses the hosts file a little differently.

Good luck, I could barely make sense of it.

http://www.macwrite.com/criticalmass/%20mac-os-x-hosts-panther.php

Enjoy!

Rower_CPU
Nov 17, 2004, 05:34 PM
Yeah, I came across that one, too but all the other tutorials seemed more straightforward.

Guess I'll give it a shot...though I'm not convinced my hosts settings are wrong, since I can ping "LARC" and it resolves to 127.0.0.1.

aus_dave
Nov 17, 2004, 06:27 PM
I'm no Unix buff so I use this script (http://patrickgibson.com/news/andsuch/000091.php) to set up my local sites so that they can be accessed by http://clientname. It works great and makes life simple :D.

I still have some issues viewing dynamic sites across a network (I think it's something to do with include paths in PHP, dots and slashes :o).

Rower_CPU
Nov 17, 2004, 06:57 PM
That script seems to work great - but I'm still stuck with non-functioning virtual hosts on both machines I've tried.

I've tried different virtualhost names and paths on a PowerBook and a PowerMac (both running 10.3.6) and neither one works. The only thing I can think of now is that the PHP/MySQL install I've done on these machines is interfering somehow...

aus_dave
Nov 17, 2004, 07:46 PM
Just to keep the ideas coming...

Can you see anything at http://127.0.0.1/virtualhostname/?

That works for me too although the paths etc. are out of whack.

Rower_CPU
Nov 17, 2004, 09:05 PM
OK, I've gotten one to work with a folder in my ~/Sites directory using the script from Patrick's site...but anything in /Library/WebServer/Documents/ or /Volumes seems not to work. I know I'm modifying the file that results from that script correctly to repoint to the directories I want - still not sure why it's not working. :confused:

update - Finally! It's working great now.

Thanks again for all the help everyone. Not sure why I had such trouble, but I'm glad it's working now. :)

maxvamp
Nov 18, 2004, 12:55 AM
Welcome to the wonderful world of UNIX

Max.