Accessing virtual hosts off another Mac on a local network

freaky

OSXer
I have a local network set up and have my imac serving files with Apache/PHP. Everything works fine when entering the projectname in Safari on the iMac, but when I punch in the same name on my PowerBook (in my local network), it goes to the root directory of where my files are on the iMac. Can somebody tell me what I need to do to get it to go to it's folder inside the root directory?

Here's an example of what I have in my settings:

PowerBook's /etc/hosts file:

192.168.1.103 projectname

When I enter http://projectname in Safari on the PowerBook it goes to the root folder (which is /Volumes/Websites)

iMac's /private/etc/httpd/httpd.conf file:

NameVirtualHost projectname:80

<VirtualHost projectname>
ServerName projectname
DocumentRoot /Volumes/Websites/projectname.com
</VirtualHost>

I ran the apacheconfigtest and the only errors that came up are NameVirtualHost projectname:80 has no VirtualHosts, but the Syntax checked out OK so it should work as far as I can tell. I have also restarted Apache through the System Config section as well.

Any help would be greatly appreciated.
 
Try adding a trailing slash after the DocumentRoot, as such:
DocumentRoot /Volumes/Websites/projectname.com/
 
I tried removing the '.' but unfortunately it didn't help. It's strange that it pulls up without any problems on the computer Apache's running on but it doesn't on other computers on the network. Do you have any other ideas?
 
If you type in the absolute path name (eg the IP address followed by the path from the server root to where your site is), what happens? Also, have you tried setting up other virtual hosts?
 
If I go to http://IPADDRESSOFLOCALSERVER/site.com, it says failed to load, but if I go to http://imac/site.com it forwards to http://imac.local/site.com and the local site comes up.

EDIT: I was putting in the wrong IP Address before. When I put in the correct address/domain.com it loaded without any problems.

I have several other virtual hosts set up but they are all in the same format as I described above. The only work on the machine they are hosted on and I cannot connect to them directly on any other computers on the network.

Do you have any other ideas?
 
You didn't bother to read the docs like it tells you to, did you?

Now when a request arrives, the server will first check if it is using an IP address that matches the NameVirtualHost. If it is, then it will look at each <VirtualHost> section with a matching IP address and try to find one where the ServerName or ServerAlias matches the requested hostname. If it finds one, then it uses the configuration for that server. If no matching virtual host is found, then the first listed virtual host that matches the IP address will be used.

As a consequence, the first listed virtual host is the default virtual host. The DocumentRoot from the main server will never be used when an IP address matches the NameVirtualHost directive. If you would like to have a special configuration for requests that do not match any particular virtual host, simply put that configuration in a <VirtualHost> container and list it first in the configuration file.

This:

Code:
NameVirtualHost projectname:80

<VirtualHost projectname>
ServerName projectname
DocumentRoot /Volumes/Websites/projectname.com
</VirtualHost>

needs to be this:

Code:
NameVirtualHost projectname:80

<VirtualHost projectname[b]:80[/b]>
ServerName projectname
DocumentRoot /Volumes/Websites/projectname.com
</VirtualHost>
 
Well, that's the right 'problem' for the description (getting referred to the default VirtualHost). I think you're probably trying to go to an invalid host. Could you send me a copy of the httpd.conf file?
 
dlloyd,

I managed to get it working by just using one line of "NameVirtualHost *" then <VirtualHost *> for each host that is set up. I guess it selects the correct VirtualHost according to the name of the ServerName. Thanks for all of your help through this.
 
Back
Top