Solved

Apache2 and Virtual Hosts

Posted on 2004-08-05
7
1,645 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility

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
Comment Utility
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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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.
Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
The viewer will learn how to dynamically set the form action using jQuery.
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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now