Forum Moderators: phranque

Message Too Old, No Replies

VirtualHost Problem

         

acer34e

3:59 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



I'm having trouble setting up a VirtualHost on my web server. It's a staging server for web sites I'm designing. I don't have much experience with Apache, but it was easy enough to set up with one domain name. I now have two domain names pointing to it and wanted to set up VirtualHosting, but I seem to be messing the httpd.conf file up. If someone can tell me what I'm doing wrong I'd appreciate it:

### Section 3: Virtual Hosts
#
# VirtualHost: If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs-2.0/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# Use name-based virtual hosting.
#
NameVirtualHost XX.XXX.XXX.XXX
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
#
<VirtualHost XX.XXX.XXX.XXX:80>
ServerAdmin admin@test1.com
DocumentRoot "C:/Apache2/htdocs/test1"
ServerName www.test1.com
ServerAlias www.test1.com *.test1.com
ErrorLog logs/test1.com-error_log
CustomLog logs/test1.com-access_log common
</VirtualHost>
#
<VirtualHost XX.XXX.XXX.XXX:80>
ServerAdmin admin@test2.com
DocumentRoot "C:/Apache2/htdocs/test2"
ServerName www.test2.com
ServerAlias www.test2.com *.test2.com
ErrorLog logs/test2.com-error_log
CustomLog logs/test2.com-access_log common
</VirtualHost>

When either domain is entered, it goes to the default htdocs directory.

[edited by: jdMorgan at 2:47 am (utc) on Mar. 17, 2006]
[edit reason] No code dumps, please. [/edit]

jdMorgan

6:09 pm on Mar 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, that code snippet contains a good hint:
# Please see the documentation at
# [httpd.apache.org...]
# for further details before you try to setup virtual hosts.

Jim

mack

6:22 pm on Mar 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



<VirtualHost *>
ServerName www.example.com
DocumentRoot /home/Joe/public_html/
ScriptAlias /cgi-bin/ /home/Joe/public_html/cgi-bin/
CustomLog /home/Joe/logs/access.log combined
</VirtualHost>

Thats what I use.

Remember you need to restart apache before the changed take effect. Always make a backup just incase things get broken.

Another importaint aspect to take into account: If you have the server set up on your local network you may not be able to view the sites using their domain name. Domain name requests are designed to come from the outside world, you need to add an entry to your hosts file in order to be able to view domain sites directly from within your lan.

Mack.