Solved

Apache2 and Virtual Hosts

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

Easy, flexible multimedia distribution & control

Coming soon!  Ideal for large-scale A/V applications, ATEN's VM3200 Modular Matrix Switch is an all-in-one solution that simplifies video wall integration. Easily customize display layouts to see what you want, how you want it in 4k.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Restore Server 2012 R2 Registry 4 106
Facebook React and SyntheticEvents 6 70
NAS - HP DataVault X510 and Windows Home Server 14 51
VMware vSAN 6.5 usage example and caveats 11 79
VM backups can be lost due to a number of reasons: accidental backup deletion, backup file corruption, disk failure, lost or stolen hardware, malicious attack, or due to some other undesired and unpredicted event. Thus, having more than one copy of …
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…
This tutorial will walk an individual through the process of configuring basic necessities in order to use the 2010 version of Data Protection Manager. These include storage, agents, and protection jobs. Launch Data Protection Manager from the deskt…
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…

856 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