Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble configuring virtual hosts 1

Status
Not open for further replies.

vegomatic

IS-IT--Management
Aug 22, 2008
20
US
Hello:
We are running
Server version: Apache/2.2.10 (Linux/SUSE)
Server built: May 5 2010 14:32:30

on Suse 11.

I am trying to configure two virtual hosts on a machine for testing: hdesk.mydomain.com and hdwiki.mydomain.com. These two names are NOT in DNS, but I plan to test using the server's IP address instead of a hostname anyway.

I've tried several different things, with the end result consistently being that I can get to EITHER hdesk OR hdwiki but not both.
The important part of hdesk.conf looks like this:
<VirtualHost *:80>
ServerAdmin me@localhost
ServerName hdesk.mydomain.com
DocumentRoot /srv/www/htdocs/blogs


and the important part of hdwiki.conf looks like this:
<VirtualHost *:80>
ServerAdmin me@localhost
ServerName hdwiki.mydomain.com
DocumentRoot /srv/


Important lines in listen.conf are
Listen 80
and
NameVirtualHost *:80

When I run apache2ctl configtest, I get Syntax OK.

When I browse to IP address>/hdesk I get the blog that's there.
When I browse to IP address/hdwiki, I get Object not found.

If I change the line in listen.conf from
NameVirtualHost *:80
to
NameVirtualHost <server's IP address>:80
and run apache2ctl configtest, the error I get is:

[Wed Feb 23 14:00:15 2011] [warn] _default_ VirtualHost overlap on port 80, the first has precedence
[Wed Feb 23 14:00:15 2011] [warn] NameVirtualHost <server's IP address>:80 has no VirtualHosts


What am I missing?

Thanks in advance for any help!

veg
 
Why do you have so many separate .conf files? How are they being included into httpd.conf? You have more moving parts than you need, which makes debugging a pain.

Put this in httpd.conf:
Code:
NameVirtualHost *:80
<VirtualHost *:80>
</VirtualHost>
Put this in hdesk.conf:
Code:
<VirtualHost *:80>
    ServerName hdesk.mydomain.com
    ServerAlias [URL unfurl="true"]www.hdesk.mydomain.com[/URL]
    DocumentRoot /srv/[URL unfurl="true"]www/htdocs/blogs[/URL]
</VirtualHost>
Put this in hwiki.conf:
Code:
<VirtualHost *:80>
    ServerName hdwiki.mydomain.com
    ServerAlias [URL unfurl="true"]www.hdwiki.mydomain.com[/URL]
    DocumentRoot /srv/[URL unfurl="true"]www/htdocs/wikis[/URL] 
</VirtualHost>

The first seemingly blank VirtualHost is a work-around to prevent only the first declared subdomain from being the only visible subdomain.
 
Another suggestion if you are going to be using the IP for testing and not names sites is to temporarily have one of them listening on port 80 and the other listening on port 81. That way when you go to 12.34.56.789:80 you will get one site and when you go to 12.34.56.789:81 you will get the other.

When you finally configure your nameserver to recognize the subdomains you will be able to have them all listening on port 80.

 
When apache is configured to use Name based virtual hosting and it can't figure out the name being requested, it will always serve the first virtual host. And all path related info will be relative to that document root.

Since you're connecting by IP address and not really using names, you need to create another VirtualHost before the other to (that are not being used anyway). The DocumentRoot of this VirtualHost needs to be the htdocs folder so that the subdirectory folder are both correct under that

Code:
<VirtualHost *:80>
    ServerAdmin me@localhost
    ServerName toplevel.mydomain.com
    DocumentRoot /srv/[URL unfurl="true"]www/htdocs[/URL]
</VirtualHost>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top