Solved

Virtual Hosts on Apache2 and server root

Posted on 2004-08-05
4
1,055 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
This article is an update and follow-up of my previous article:   Storage 101: common concepts in the IT enterprise storage This time, I expand on more frequently used storage concepts.
This tutorial will show how to configure a new Backup Exec 2012 server and move an existing database to that server with the use of the BEUtility. Install Backup Exec 2012 on the new server and apply all of the latest hotfixes and service packs. The…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

706 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