[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Apache2 and Virtual Hosts

Posted on 2004-08-05
7
Medium Priority
?
1,653 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 400 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

Workplace bullying has increased with the use of email and social media. Retain evidence of this with email archiving to protect your employees.
Microsoft will be releasing the Windows 10 Creators Update in just a matter of weeks. Are you prepared? Follow these steps to ensure everything goes smoothly and you don't lose valuable data on your PC.
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

650 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