Solved

Apache2 and Virtual Hosts

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

919 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