Unable to configure name-based virtual hosting

michaelsanford

Translator, Web Developer
I wouldn't have assumed this woudl present any problems, but it has, to no end in fact.

I have my Slackware machine behind a NAT, natting http and ftp to it. I also have a residential ADSL with a dynamic IP, so I use no-ip.org's service to bind to
sonia.bounceme.net (trying to set up a web site for a friend)
michaelsanford.myvnc.com (my stuff)
trogdor.myvnc.com (legacy server name getting migrated to above)

They all, of course, point to the same machine. I also have wildcards enabled on the DNS, which means that I can prefix the subdomain with another subdomain, like blog.sonia.bounecme.net and it will resolve to me and pass that as the host string for processing.

Now for some code:
/etc/hosts
# For loopbacking.
127.0.0.1 localhost
#127.0.0.1 trogdor.local trogdor
127.0.0.1 michaelsanford.myvnc.com sonia.bounceme.net michaelsanford trogdor


[root@0 ~]# cat /etc/HOSTNAME

michaelsanford.myvnc.com


Ok so the server knows itself primarily as michaelsanford.myvnc.com and the login prompts "michaelsanford login: ". I've also added "michaelsanford" as its host name in my router (since the rest just didn't fit).

Now, for httpd.conf
Section 3
NameVirtualHost *:80
# Main Host
<VirtualHost *:80>
ServerName michaelsanford.myvnc.com
ServerAdmin trogdor_at_michaelsanford.com
ServerAlias *.michaelsanford.myvnc.com michaelsanford.myvnc.com
DocumentRoot /var/www/htdocs
ErrorLog /var/log/apache/michaelsanford_error_log
CustomLog /var/log/apache/michaelsanford_access_log common
</VirtualHost>

# Sonia's Host
<VirtualHost sonia.bounceme.net:80>
ServerName sonia.bounceme.net
ServerAdmin trogdor_at_michaelsanford.com
ServerAlias *.sonia.bounceme.net sonia.bounceme.net
DocumentRoot /home/sonia/public_html
#BindAddress sonia.bounceme.net
ErrorLog /home/sonia/logs/sonia_error-log
CustomLog /home/sonia/logs/sonia_access-log common
Options -Indexes +ExecCGI
</VirtualHost>

[root@0 ~]# httpd -S
VirtualHost configuration:
70.48.55.177:80 sonia.bounceme.net (/etc/apache/httpd.conf:1029)
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server michaelsanford.myvnc.com (/etc/apache/httpd.conf:1019)
port 80 namevhost michaelsanford.myvnc.com (/etc/apache/httpd.conf:1019)

[root@0 ~]# apachectl start
/usr/sbin/apachectl start: httpd could not be started


:eek: Any ideas ? If anyone has virtual hosting working and feels like sending me their httpd.conf so I can compare I would be eternally indebted.
 
I am having similar problems. I have no trouble setting up the webserver to point to /Library/Webserver/Documents and having that single site available to the rest of the world. BUT, when I try to set up a couple VirtualHost(s) I end up getting 403 Forbidden - dont have access to / on this server.

It seems as though configuring apache is not enough to get this working. I had this working fine in Jaguar and I am at a loss to explain why it does not work in Panther.

There are several resources on the net that suggest that it is necessary to add entries into the /etc/hosts file and you must create new "machine" entries with NetInfo. There are also docs out there that show you how to set it up under your user/Sites folder (and I know _I_ dont want to do it that way). Also, for those that would say 'use IP based' - I dont think I can as I do not have a static IP.

I just dont remember it being this difficult with Jaguar.
 
It seems to me as though you don't have Options +Indexes enabled on those folders. When you set up NBVH your "main server" configured in Section 1 never gets called, so you'd need to define that in each of your VirtualHost containers, or specified through an .htaccess file.

Mind if I have a look at Sections 1 and 3 of your httpd.conf ? msanford AT michaelsanford.com

PS I'm using Apache 1.33 on my Slackware box, not 1.28 which (I believe) is the current OS X version.
 
Well.... no, I think its there... I sent you the file. Its almost identical to
my RH9 box that IS working. Sad days that it is easier to config Linux than Mac. IMHO.
 
It may be that hedged 'almost' identical that's making it not work. Have you set the folders to a+rx ? Also it might not be a bad idea to include your virtual hosts in /etc/hosts since I know httpd consults that file for a few things. Just add it to the end of the line "127.0.0.1 first.com second.com etc.com"

Then again, I can't get mine working, so take my advice with a grain of salt ;)
 
yep, reading and executing are set. tried the localhost and the netinfo tricks - pretty much been beating my head against this for over 12 hours..... me = stoopid.
 
You've left out your directory tags which should be included for best results.

Try this for a super basic setup:

/etc/httpd/httpd.conf

NameVirtualHost 192.168.2.3:80 (match to your internal IP)
## default site
Include /etc/httpd/conf.d/*.conf

/etc/httpd/conf.d/virtualhost01.conf

## virtualhost01.conf

<VirtualHost 192.168.2.3:80>
ServerName www.virtualhost.com
ServerAlias virtualhost.com (if needed)
ServerAdmin webmaster@virtualhost.com
DocumentRoot "/home/users/path/to/html"
DirectoryIndex index.html index.php
CustomLog /var/log/httpd/access_log combined

<Directory "/home/users/path/to/html">
Options All (set as you need)
AllowOverride AuthConfig (set as you need)
</Directory>
</VirtualHost>

Good luck.
 
Thanks for the suggestion.

ADDED :
NameVirtualHost 172.16.1.34

<VirtualHost 172.16.1.34>
ServerName bageyes.dyndns.org
DocumentRoot "/Library/Webserver/Documents"
<Directory "/Library/Webserver/Documents">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

and I still get :

"GET / HTTP/1.1" 403 285
 
Code:
#i dont use this line in my virtual host setup. I have it commented
#NameVirtualHost *:80  
# Main Host
<VirtualHost *:80>
ServerName michaelsanford.myvnc.com
ServerAdmin trogdor_at_michaelsanford.com
ServerAlias *.michaelsanford.myvnc.com michaelsanford.myvnc.com
DocumentRoot /var/www/htdocs
ErrorLog /var/log/apache/michaelsanford_error_log
CustomLog /var/log/apache/michaelsanford_access_log common
</VirtualHost>

# Sonia's Host
<VirtualHost *:80>
ServerName sonia.bounceme.net
ServerAdmin trogdor_at_michaelsanford.com
ServerAlias *.sonia.bounceme.net sonia.bounceme.net
DocumentRoot /home/sonia/public_html
ErrorLog /home/sonia/logs/sonia_error-log
CustomLog /home/sonia/logs/sonia_access-log common
Options -Indexes +ExecCGI
</VirtualHost>

make sure /home/sonia/public_html can be read by user www - (as well as the path to it).
 
appologies to micheal for hijacking his thread.

But I found my solution, and it has NOTHING to do with /etc/hosts or NetInfo. Evidently the directories that I created for each Virtual Host were done as ROOT and even though the permissions were 755, it would 403 me every time. rm'd them and re-created as my user and all is well.
 
Back
Top