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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

need some help on vhosts

Status
Not open for further replies.

hookahmasta

IS-IT--Management
Aug 5, 2005
31
US
I'm trying to set up 2 vhosts, each with its own unique web address, on one apache server. It worked for a while, but all of a sudden, it stopped working; now, both vhosts now goes to one of the vhost. Here's the configuration files for each vhost

The one that both vhosts are going to

<VirtualHost (DocumentRoot (Directory of website)
<Directory (Directory of website)>
allow from all
Options +Indexes
</Directory>
</VirtualHost>

The one not working (BTW, it's a redirect to somewhere else, but when I take off the redirect, it makes no difference)

<VirtualHost (DocumentRoot (Directory of website)
ServerName <Directory "(Directory of website)">
allow from all
Options +Indexes
</Directory>
#RedirectPermanent / (Website it redirects to)
</VirtualHost>

Here's what I found out so far.....

If I delete the vhosts that seems to have "Taken Over", the redirect works again. If I renamed the index.html to "break" the "taken over" vhosts, both sites break. I tried to delete the vhosts, and redo the vhost, with a different website directory, but that vhost still takes over.

I'm new at apache and need some help... any pointers would be great....
 
You want to use name based addressing. This means that apache will look for a ServerName that matches the one requested. It should look for all addresses on port 80. So ALL vhost containers should look like this:

<VirtualHost *:80>

Each vhost MUST have a ServerName directive defined. Like this:

ServerName mydomain.com
ServerAlias
Each vhost must also have a DocumentRoot. This is the path to the directory that holds all the web pages. One last thing is to make sure that "NameVirtualHost *:80" is uncomented. restart apache and everything should work like a champ.
 
I guess the virtual host that is always being used is the first one defined in the configuration? Apache uses the first defined virtual host as default if no matching virtual host is found (there is also a special _DEFAUL_ that can be used, but I think that's only for IP-based virtual hosts).

That problem is most likely that there is no virtual host match and therefore the first one defined is being used. Maybe that goes for requests for both address, it only seems to work for one of the address as the default host is the one it should have matched.

This is how I would configure (Apache 2.0):
[tt]
#Use name-based virtual hosting (port 80)
NameVirtualHost *:80

#Block all invalid addresses (first virtual host is default)
<VirtualHost *:80>
# The servers internal name
ServerName abc.def.ghe

<Location />
Deny from all
</Location>
</VirtualHost>

<VirtualHost *:80>
ServerName address1

# Do whatever...
</VirtualHost>

<VirtualHost *:80>
ServerName address2

# Do whatever...
</VirtualHost>
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top