Solved

Virtual Hosts on Apache2 and server root

Posted on 2004-08-05
4
1,056 Views
Last Modified: 2013-11-18
Hi everyone
I have apache2 installed in /usr/local/apache. In the conf dir is my main httpd.conf file. It's virtual host settings are defined as:

NameVirtualHost *:80
Include /usr/local/apache/conf/vhosts/*.conf

In the directory conf/vhosts I have the virtual hosts defined in their seperate files, a typical site looks like this:

<VirtualHost *:80>
ServerName website.com
ServerAlias www.website.com 
DocumentRoot /www/sites/w/website/public_html
ScriptAlias /cgi-bin/ /www/sites/w/website/cgi-bin
ErrorLog /www/sites/w/website/logs/error.log
CustomLog /www/sites/w/website/logs/access.log combined
Alias /stats /www/sites/w/website/stats
<Directory />
Options Includes Indexes FollowSymLinks
</Directory>
</VirtualHost>

The problem is that when I type the the ip address of the server directly into the browser the first alphabetical virtual host site is displayed. e.g if I have a-site.conf, b-site.conf, c-site.conf etc in the vhosts folder then a-site.conf is displayed when the IP Address is typed in.

does anyone know why this would happen?

Thanks
0
Comment
Question by:fast74
4 Comments
 
LVL 6

Accepted Solution

by:
philjones85 earned 50 total points
ID: 11729261
It probably doesn't know which virtual host to send it to, so it sends it to the first by default.

I've always setup a "default" configuration in the main httpd.conf file which I always get when typing the ip directly.

If you want a specific virtual host to come up when the ip is typed, try adding that as a server alias
  ServerAlias www.website.com  XXX.XXX.XXX.XXX
0
 
LVL 15

Assisted Solution

by:periwinkle
periwinkle earned 50 total points
ID: 11743077
philjones is correct - Apache serves the first page that matches the IP address if an IP address is given in the URL.

If a-site.conf, b-site.conf, c-site.conf all have the same IP address specification, then Apache has no way of determining which site to serve.  If you have unique IP addresses, then you can do:

<VirtualHost xxx.xxx.xxx.xxx:80>

where xxx.xxx.xxx.xxx is the unique IP address.  
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to fix error ""Failed to validate the vCentre certificate. Either install or verify the certificate by using the vSphere Data Protection Configuration utility" when you are trying to connect to VDP instance from Vcenter.
By default, Carbonite Server Backup manages your encryption key for you using Advanced Encryption Standard (AES) 128-bit encryption. If you choose to manage your private encryption key, your backups will be encrypted using AES 256-bit encryption.
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now