goland
03-12-2003, 11:04 PM
Hi,
I'm trying to set up virtual hosting using Apache 2 on Win2k. I've 1 domain name (www.mydomain.com) but I am trying to set up a sub domain as sub.mydomain.com. I've got the DNS setup so that it's all pointing to my server and all I need to do is configure my httpd.conf.
This is the virtual hosts section of my httpd.conf
NameVirtualHost *
<VirtualHost *>
ServerName www.mydomain.com
DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"
</VirtualHost>
<VirtualHost *>
ServerName sub.mydomain.com
DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs/sub"
</VirtualHost>
When I try to load sub.mydomain.com in my browser I get the error:
PHP Fatal error: Unable to open C:\Program Files\Apache Group\Apache2\htdocs/index.html in Unknown on line 0
I was thinking that the spaces in the path might be a problem so I tried making some fake network mappings to point farther into the path so I wouldn't have the spaces in the path but that didn't help. I have PHP enabled on the server but it's working flawlessly (so far). I'm probably just making a simple mistake but I can't seem to see it.
Any help would be appreciated,
Thanks
Have you tested your PHP installation to make sure that was working okay (y'know the whole 127.0.0.1 thing)?
Also, check to make sure that your conf file in the Directory Index section includes a reference to a index.php file like so (or you can specify a DirectoryIndex setting in each individual Virtual Host):
DirectoryIndex index.html index.html.var index.php
Beyond that the only other thing I could see in what you have is it may be a good idea to include a ServerAlias line in each VirtualHost container. Here's what I did with my VHosts as an example (yes there's alot of 'em but I wanted to customize the heck out of it so justaboutanything.mydomains.com would get you to a specific place - like almost every subpage has it's own domain name. :D):
Note that the first one is a generic catch-all so that if someone types in something that I DON'T have here (like qwerty.stephenqr.com) ... it'll revert to the first one by default - the main root directory where I have only a page giving an "Oops!" or a personalized "404" kinda message.
(see next posts)
NameVirtualHost *
<VirtualHost *>
DocumentRoot "F:/Apache2/htdocs"
</VirtualHost>
<VirtualHost *>
ServerName forum.sbmountainhomes.com
ServerAlias forum.sbmountainhomes.com
ServerAdmin stephen@sbmountainhomes.com
DocumentRoot "F:/Apache2/htdocs/sbmountainhomes/phpBB2"
DirectoryIndex index.php
CustomLog logs/sbmountainhomes_access.log common
ErrorLog logs/sbmountainhomes_error.log
</VirtualHost>
<VirtualHost *>
ServerName stats.sbmountainhomes.com
ServerAlias stats.sbmountainhomes.com
ServerAdmin stephen@sbmountainhomes.com
DocumentRoot "F:/Apache2/htdocs/sbmountainhomes/analog 5.31"
DirectoryIndex report.html
CustomLog logs/sbmountainhomes_access.log common
ErrorLog logs/sbmountainhomes_error.log
</VirtualHost>
<VirtualHost *>
ServerName www.sbmountainhomes.com
ServerAlias sbmountainhomes.com *.sbmountainhomes.com
ServerAdmin stephen@sbmountainhomes.com
DocumentRoot "F:/Apache2/htdocs/sbmountainhomes"
DirectoryIndex index.html
CustomLog logs/sbmountainhomes_access.log common
ErrorLog logs/sbmountainhomes_error.log
</VirtualHost>
<VirtualHost *>
ServerName forum.stephenqr.com
ServerAlias forum.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/phpBB2"
DirectoryIndex index.php
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName aybabtu.stephenqr.com
ServerAlias aybabtu.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/personal/aybabtu"
DirectoryIndex index.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName coolmon.stephenqr.com
ServerAlias coolmon.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/personal/coolmon"
DirectoryIndex coolmon.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName humorous.stephenqr.com
ServerAlias humorous.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/personal/humorous"
DirectoryIndex index.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName photos.stephenqr.com
ServerAlias photos.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/personal/photos"
DirectoryIndex index.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName handfasting.stephenqr.com
ServerAlias handfasting.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/personal/photos/handfasting"
DirectoryIndex index.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName huntington.stephenqr.com
ServerAlias huntington.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/personal/photos/huntington"
DirectoryIndex index.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName miscphotos.stephenqr.com
ServerAlias miscphotos.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/personal/photos/misc"
DirectoryIndex index.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName mountains.stephenqr.com
ServerAlias mountains.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/personal/photos/mountains"
DirectoryIndex index.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName thanksgiving.stephenqr.com
ServerAlias thanksgiving.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/personal/photos/thanksgiving"
DirectoryIndex index.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName poetry.stephenqr.com
ServerAlias poetry.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/personal/poetry"
DirectoryIndex index.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName smilies.stephenqr.com
ServerAlias smilies.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/personal/smilies"
DirectoryIndex index.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName ut.stephenqr.com
ServerAlias ut.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/ut"
DirectoryIndex index.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName stats.stephenqr.com
ServerAlias stats.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr/analog 5.31"
DirectoryIndex report.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
<VirtualHost *>
ServerName www.stephenqr.com
ServerAlias stephenqr.com *.stephenqr.com
ServerAdmin admin@stephenqr.com
DocumentRoot "F:/Apache2/htdocs/stephenqr"
DirectoryIndex index.html
CustomLog logs/stephenqr_access.log common
ErrorLog logs/stephenqr_error.log
</VirtualHost>
...continued ...
... continued ...
<VirtualHost *>
ServerName forum.ewicca.com
ServerAlias forum.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/phpBB2"
DirectoryIndex index.php
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName wicca.ewicca.com
ServerAlias wicca.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca"
DirectoryIndex index.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName history.ewicca.com
ServerAlias history.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca"
DirectoryIndex history.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName holidays.ewicca.com
ServerAlias holidays.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca"
DirectoryIndex holidays.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName name.ewicca.com
ServerAlias name.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca"
DirectoryIndex name.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName wlinks.ewicca.com
ServerAlias wlinks.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca"
DirectoryIndex wlinks.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName bos.ewicca.com
ServerAlias bos.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca/bos"
DirectoryIndex index.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName divination.ewicca.com
ServerAlias divination.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca/divination"
DirectoryIndex index.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName dreams.ewicca.com
ServerAlias dreams.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca/divination"
DirectoryIndex dreams.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName numerology.ewicca.com
ServerAlias numerology.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca/divination"
DirectoryIndex numerolo.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName pendelum.ewicca.com
ServerAlias pendelum.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca/divination"
DirectoryIndex pendelum.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName saxon.ewicca.com
ServerAlias saxon.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca/divination"
DirectoryIndex saxon.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName scrying.ewicca.com
ServerAlias scrying.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca/divination"
DirectoryIndex scrying.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName runes.ewicca.com
ServerAlias runes.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca/divination/runes"
DirectoryIndex index.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName tarot.ewicca.com
ServerAlias tarot.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wicca/divination/tarot"
DirectoryIndex index.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName wolves.ewicca.com
ServerAlias wolves.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wolves_and_dragons/wolves"
DirectoryIndex index.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName dragons.ewicca.com
ServerAlias dragons.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/wolves_and_dragons/dragons"
DirectoryIndex index.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName stats.ewicca.com
ServerAlias stats.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca/analog 5.31"
DirectoryIndex report.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
<VirtualHost *>
ServerName www.ewicca.com
ServerAlias ewicca.com *.ewicca.com
ServerAdmin admin@ewicca.com
DocumentRoot "F:/Apache2/htdocs/ewicca"
DirectoryIndex index.html
CustomLog logs/ewicca_access.log common
ErrorLog logs/ewicca_error.log
</VirtualHost>
the end :)
whowrotewhat
07-17-2005, 06:28 PM
I've succesfully implemented virtual hosts
using the information supplied on this page: http://www.onlamp.com/pub/a/apache/2003/07/24/vhosts.html
Hi,
It was a nightmare to chase down, but I've finally
got my Win2k Apache2 PHP5 box with multiple
VirtualHosts, and the ability to access any of the
VirtualHosts from either the same box, or computers
connected to my Nic or Lan.
With file named vhost, each ServerName must be resolvable
by DNS and entered into hosts file on each PC -that's
poor man's DNS-There is hosts and hosts.sam files somwhere
down the windows or winnt folder
We modify the lmhosts file to resolve
names to IPs when we get folks to VPN
into the network (to map our server
names without needing to mess with
their current DNS/WINS settings)
On a win2k/xp machine, look here:
c:\windows\system32\drivers\etc\lmhosts.sam
c:\windows\system32\drivers\etc\hosts
hosts should look like this:
++++++++++++++++++++++++++++++
IMPORTANT NOTE:
Don't Need to touch the
lmhosts.sam file, unless you
prefer VPN mode, which might
actually be a lot easier,
rather than having to modify
the hosts file on all machines.
Might Leave hosts alone and
try the vpn mode lmhosts.sam
file instead.
+++++++++++++++++++++++++++++++
Well, I first installed Apache2 w/php5, and got that
working, could access the DocumentRoot in IE by typing
in either "localhost", or "127.0.0.1", 192.168.0.1, or
even by typing in the computer name "rack" (no quotes).
From the other machines on my lan, I could originally
only call the main server documentroot by typing in
the ip address of my nic, 192.168.0.1, or by typing in
the computer name "rack".
Well, from there, I opened the Apache
httpd.conf file and verify the following:
Substitute your desired folder paths or names,
and create the folder full path:
Keep in mind that the top virtualhost
is always the main server account, always,
no exceptions, a fallback, & keep it that way.
+++++++++++++++++++++++++
Top to bottom:
In section2:
+++++++++++++++++++++++++++
# These just set the DocumentRoot
<Directory "C:/East/Web/vhost1">
DocumentRoot "C:/East/Web/vhost1"
+++++++++++++++++++++++++++
In section3:, BOTTOM OF THE PAGE
++++++++++++++++++++++++++
# Use name-based virtual hosting.
#
# NameVirtualHost *:80
NameVirtualHost *:80
# ==========================server default======
# ==============================vhost1==========
<VirtualHost *:80>
DocumentRoot "C:/East/Web/vhost1"
ServerName vhost1
ServerAlias localhost rack
ServerAdmin whowrotewhat@yahoo.com
DirectoryIndex index.html index.php index.htm
</VirtualHost>
# ===========================domain1 offline ====
# =============================vhost2============
<VirtualHost *:80>
DocumentRoot "C:/East/Web/vhost2"
ServerName vhost2
ServerAlias mikey.test
ServerAdmin whowrotewhat@yahoo.com
DirectoryIndex index.html index.php index.htm
</VirtualHost>
# =============================domain1 online ===
# =============================vhost3============
<VirtualHost *:80>
ServerName vhost3
ServerAlias www.mikey.com mikey.com
ServerAdmin whowrotewhat@yahoo.com
DocumentRoot "C:/East/Web/vhost3"
DirectoryIndex index.html index.php index.htm
</VirtualHost>
# ==========================end vhosts==========
Now, in win2k, go to
c:\winnt\system32\drivers\etc\ and open
with notepad, a file called "hosts"
(I left the lmhost.sam file alone, for now,
but this might be a better choice/option)
Note: My TCP-IP Nic Network Card IP is 192.168.0.1
127.0.0.1 is default server IP
++++++++++++++++++++++++++
I entered this, into mine:
127.0.0.1 localhost
192.168.0.1 vhost1
192.168.0.1 rack
192.168.0.1 vhost2
192.168.0.1 mikey.test
192.168.0.1 vhost3
192.168.0.1 www.mikey.com
192.168.0.1 mikey.com
+++++++++++++++++++++++
or with the lmhosts, try this:
127.0.0.1 localhost #PRE
+++++++++++++++++++++++++++
-make backups of both files first, and try the hosts
file first. note, the "#" for LMHOSTS is NOT for
commenting, but for 'instructions' (pre = preload),
but that file has a much longer built-in readme
that I won't post here but that you'll see when
you edit it in notepad.oh, and I don't have a
win98 machine handy, so you'll have to search
for the file's locations' yerself.
++++++++++++++++++++++++++++++++++++++++++++++++++ ++
For example, when I give other people accross the
internet Http://myipaddress/forum, it <b> doesn't
</b> bring up the index.php. And that goes for
everything else unless I give them the specific
url to the page like Http://myipaddress/forum/index.php.
But when I (the host comp where phpdev is installed
in) type in the address above it works even if I do
not include the /forum/index.php. How do i config so
that when I give other people the address like
Http://myipaddress/forum it brings up the page
index.php automatically?
in your httpd.conf you will see a list of things similar to
Alias /site/ "C:/phpdev5/www/phpwebsite_en/"
<Directory "C:/phpdev5/www/phpwebsite_en/">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
DirectoryIndex index.php index.htm
</Directory>
add one that reads
Alias /forum/ "C:/phpdev5/www/forum/"
<Directory "C:/phpdev5/www/forum/">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
DirectoryIndex index.php
</Directory>
this should work
wow, Larry - my hero.... it now works a treat
+++++++++++++++++++++++++++++++++
By clicking on a link, Apache will feed him the local or the remote copy of index.html for the client he selects.
This requires the local client domains to be
entered into his windows/system32/drivers/etc/hosts file:
127.0.0.1 localhost
127.0.0.1 local-client_a.com
127.0.0.1 local-client_b.com
Apache then looks up 127.0.0.1 in its vhost
address sets table and finds three vhosts
associated with the address. It then scans
for a ServerName in order of entry that
matches local-client_a.com. If it fails to
find a match, it will go back to the first
entry for 127.0.0.1 (localhost) and use it.
It does, however, find a match with the
second vhost, so it looks in that vhost's
root directory (/var/www/client_a) for the
subdirectory cgi-bin and the file search.cgi
within it. The result is that links that work
on the client's site now work locally.
++++++++++++++++++++++++++++++++++
You can insert these next two lines into a vhost block to direct Apache to display customized error messages to the user.
ErrorDocument 404 /messages/404.html
ErrorDocument 500 /messages/500.html
(create folder and message files first)
RedirectMatch permanent .html /cgi-bin/index.cgi
This directive, located inside of the vhost block, redirects clients who are looking for pages ending in .html to the main script. This is much nicer than displaying an error message.
If you have a vhost that you would like to use for more than one domain name, then you can put a ServerAlias directive inside of the vhost block to link the two domain names together.
++++++++++++++++++++++++++++++++++++++++
in virtualhosts block:
Multiple aliases single spaced apart:
ServerAlias somesite.com secondsite.com
+++++++++++++++++++++++++++++++++++
Hans,
I went into hosts file in win2k (all computers), and entered
the lan nic's ip address and domain vhost names and aliases,
I also put the virtualhost statements in apache's httpd.conf file. Thanks, Just what I was looking for. Works just fine.
Virtual hosts "name-based", what is the correct way to do
this. I'm just being cautious. What to which files
hosts? lmhosts.sam?
************************************************** ***
The file named "hosts" should be located at (on Windows 2000):
c:\Winnt\System32\drivers\etc (I believe that is correct)
I suspect it lives at the same location on XP -- but I
have not looked for it yet
file (c:\windows\system32\drivers\etc\hosts
on windws xp) with two different name entries eg
(ip # of your nic in tcp/ip)
+++++++++++++++++++++++++++++++
domain1 111.222.333.444
domain2 111.222.333.444
++++++++++++++++++++++++++++++++
duds
http://httpd.apache.org/docs-2.0/vhosts/
http://httpd.apache.org/docs-2.0/vhosts/name-based.html
With name-based virtual hosting, the server relies on the client to report the hostname as part of the HTTP headers. Using this technique, many different hosts can share the same IP address.
************************************************** *****
The first virtual host is the main server,
and the main server files are never released
to the public. You need to keep the first
virtual host as private, as _default_ keep
it seperate, and add a third .