httpd Virtual Hosts initial configuration

Support for webhosts that use CentOS
Post Reply
dgreen
Posts: 2
Joined: 2007/07/04 18:47:14

httpd Virtual Hosts initial configuration

Post by dgreen » 2007/07/04 19:05:02

I have a CentOS 4 server which is currently serving a single site located in /var/www/html. I would like to add more domains to the server using named based virtual hosting.

Following the instructions here;

http://httpd.apache.org/docs/2.0/vhosts/examples.html

I edited /etc/httpd/conf/httpd.conf as follows:

[code]# Virtual host Default Virtual Host
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName www.original-site.com

ServerSignature email
DirectoryIndex index.php index.html index.htm index.shtml
LogLevel warn
HostNameLookups off
</VirtualHost>


<VirtualHost *:80>
DocumentRoot /var/www/html/newdomain
ServerName www.newdomain.com

ServerSignature email
DirectoryIndex index.php index.html index.htm index.shtml
LogLevel warn
HostNameLookups off
</VirtualHost>[/code]

When starting the httpd service, the following appears:

[code][root@www conf]# service httpd start
Starting httpd: [Wed Jul 04 11:55:45 2007] [warn] The Alias directive in /etc/httpd/conf/httpd.conf at line 493 will probably never match because it overlaps an earlier AliasMatch.
[Wed Jul 04 11:55:45 2007] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[ OK ]
[root@www conf]#
[/code]

When I navigate to http://www.original-domain.com/ I get the page in the root of /var/www/html (which I expect). However, when I go to http://www.newdomain.com, I also get the same /var/www/html page, and not the /var/www/html/newdomain index.

Here is the output from the access log:

[code]1.2.3.4 - - [04/Jul/2007:11:58:55 -0700] "GET / HTTP/1.1" 403 5044 "-" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"
1.2.3.4 - - [04/Jul/2007:11:58:55 -0700] "GET /icons/powered_by_rh.png HTTP/1.1" 404 332 "http://www.original-domain.com/" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"


1.2.3.4 - - [04/Jul/2007:11:59:04 -0700] "GET / HTTP/1.1" 403 5044 "-" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"
1.2.3.4 - - [04/Jul/2007:11:59:04 -0700] "GET /icons/powered_by_rh.png HTTP/1.1" 404 332 "http://www.newdomain.com/" "Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"[/code]

DNS for both sites points to the IP address of my server.

My goal is to have the default page on the server as "original-site." Is this the right way to configure this?

Thank you for any help!

User avatar
WhatsHisName
Posts: 1547
Joined: 2005/12/19 20:21:43
Location: /earth/usa/nj

httpd Virtual Hosts initial configuration

Post by WhatsHisName » 2007/07/04 20:06:45

Did you define NameVirtualHost?

Also, what is line 493 in httpd.conf? Very useful info for diagnostic purposes.

dgreen
Posts: 2
Joined: 2007/07/04 18:47:14

Re: httpd Virtual Hosts initial configuration

Post by dgreen » 2007/07/04 21:01:22

That was the trick! Thank you for your help!

Also, if I wanted the two addresses "newdomain.com" and "www.newdomain.com" to point to the same directory on my server, do I need to create two entries like this?

[code]<VirtualHost *:80>
DocumentRoot /var/www/html/newdomain
ServerName newdomain.com

ServerSignature email
DirectoryIndex index.php index.html index.htm index.shtml
LogLevel warn
HostNameLookups off
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /var/www/html/newdomain
ServerName www.newdomain.com

ServerSignature email
DirectoryIndex index.php index.html index.htm index.shtml
LogLevel warn
HostNameLookups off
</VirtualHost>
[/code]

It works fine with two entries, but if I could do it in one that is preferred. Thanks again!

User avatar
WhatsHisName
Posts: 1547
Joined: 2005/12/19 20:21:43
Location: /earth/usa/nj

Re: httpd Virtual Hosts initial configuration

Post by WhatsHisName » 2007/07/04 21:14:47

Suppose that would work, but defining a ServerAlias on the line after ServerName would be a more standard way to do it.

In your case (two domains), virtual hosts would not be needed.

fishdust
Posts: 3
Joined: 2007/04/03 04:28:21

Re: httpd Virtual Hosts initial configuration

Post by fishdust » 2007/07/08 03:59:08

That worked great, thank you for the help!

Post Reply

Return to “CentOS 4 - Webhosting Support”