Forum Moderators: phranque

Message Too Old, No Replies

Some virtual hosts directed to the same directory

         

Cary

1:45 pm on Jul 7, 2006 (gmt 0)

10+ Year Member



I am new to Apache and have a problem with virtual hosting.
I set up an Apache server with Redhat Fedora 5 and 3 virtual hosts of ServerName as follow:-
1. aaa.com
2. john.aaa.com
3. XXX.no-ip.org
It worked in he last month correctly. Recently, I try to add another domain bbb.com to the same server which the DocumentRoot and ServerName is different with that of aaa.com.
After restarting Apache, it happens that both aaa.com (also john.aaa.com) and bbb.com are directed to the same directory. The case is that they are directed to the directory of the first virtual host in the list no matter which one I put first. However, XXX.no-ip.org still works correctly.
Would anybody suggest what is going wrong?

jdMorgan

2:19 pm on Jul 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is a typical problem, in that the server will serve the contents of the first VirtualHost if it cannot decide which of the others to serve; In other words, the first-listed VirtualHost is the default server.

See the Apache name-based virtual hosting documentation [httpd.apache.org], as this is usually a problem with the arguments of the "VirtualHost" directives.

Jim

Cary

2:42 pm on Jul 7, 2006 (gmt 0)

10+ Year Member



Jim,
Thank you for your reply. But I just wonder why the XXX.no-ip.com site work with no problem. I am suspecting that it is a problem of the www host on the 2 public domains in problem. Should I put www in the ServerName directive? Recently, i just put aaa.com and bbb.com as the ServerNames.

jdMorgan

3:01 pm on Jul 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Without seeing your entire config and consulting with you for 30 minutes, I can't tell what you should put in there, except generally: Make the ServerName and ServerAlias directives as specific and as unambiguous as possible, and make sure that your <VirtualHost> is defined as described in the document I linked to above; it should contain an IP address or "*" and not a hostname.

I presume that your DNS Zone file is properly configured as well.

Jim

Cary

3:14 pm on Jul 7, 2006 (gmt 0)

10+ Year Member



Jim,
I am now writing at home and do not have the config file with me. In my config file, I put <VirtualHost *:80> in all virtual hosts,
ServerName example.com
and
ServerName example.com
for the 2 public domains respectively.
Will there be any difference if someone enter http://example.com, http://www.example.com, www.example.com and example.com in a web browser?

[edited by: jdMorgan at 3:33 pm (utc) on July 7, 2006]
[edit reason] Example.com [/edit]

jdMorgan

3:30 pm on Jul 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you'll need a ServerAlias for the 'www' subdomains, or a wild-card -- for example *.example.com as the ServerName. This stuff has to specify *exactly* what you want -- the server won't guess. If the request doesn't exactly match a defined server, then it will serve pages from the default server.

Again, I suggest a serious study session with the Apache document cited above, and those that it links to.

Jim