Solved

Apache2 and Virtual Hosts

Posted on 2004-08-05
7
1,649 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 4

Accepted Solution

by:
TomDavidson earned 100 total points
ID: 11726398
The 1st VirtualHost is taken as the default site, if you don't want it to be then just insert another virtualhost before the rest perhaps in httpd.conf

NameVirtualHost *:80
*****here*****
Include /usr/local/apache/conf/vhosts/*.conf
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 11729680
you need an additional Vhost entry like:

<VirtualHost ip.ip.ip.ip:80>
ServerName ip.ip.ip.ip
 ....
0
 
LVL 38

Expert Comment

by:yuzh
ID: 11732619
Have look at the following page to learn more details about VirtualHost setup:
http://www.experts-exchange.com/Web/Web_Servers/Apache/Q_20859488.html
0
 
LVL 15

Expert Comment

by:samri
ID: 11754387

Or, http://httpd.apache.org/docs-2.0/vhosts/

>> Include /usr/local/apache/conf/vhosts/*.conf

I am not sure how apache would evaluate this statement.  Apache will take the 1st defined vhost as the default for those request that does not match any defined vhost (as TomDavidson mentioned!).

Another thing,

>> 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.

And this is normal.  Remember that when use use http://1.2.3.4/ then, the request is sent to the server (and the Host: header is 1.2.3.4), and Apache would do a match against any Vhost for ServerName (http://httpd.apache.org/docs-2.0/mod/core.html#servername) (or ServerAlias) 1.2.3.4, and it would failed to find any -- Thus, it will return the first Vhost defined (which is a-site.conf).

Also look at http://httpd.apache.org/docs-2.0/dns-caveats.html for some tips.

:)
0
 
LVL 1

Expert Comment

by:redfish0
ID: 11811320
Try editing /etc/apache2/default-server.conf
Configure and use what ever you want as your default website.  Blank page, redirect to your companies website, or what ever.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

A Bare Metal Image backup allows for the restore of an entire system to a similar or dissimilar hardware. They are highly useful for migrations and disaster recovery. Bare Metal Image backups support Full and Incremental backups. Differential backup…
In this article we will learn how to backup a VMware farm using Nakivo Backup & Replication. In this tutorial we will install the software on a Windows 2012 R2 Server.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

726 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