Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Virtual Hosts on Apache2 and server root

Posted on 2004-08-05
4
Medium Priority
?
1,084 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
4 Comments
 
LVL 6

Accepted Solution

by:
philjones85 earned 200 total points
ID: 11729261
It probably doesn't know which virtual host to send it to, so it sends it to the first by default.

I've always setup a "default" configuration in the main httpd.conf file which I always get when typing the ip directly.

If you want a specific virtual host to come up when the ip is typed, try adding that as a server alias
  ServerAlias www.website.com  XXX.XXX.XXX.XXX
0
 
LVL 15

Assisted Solution

by:periwinkle
periwinkle earned 200 total points
ID: 11743077
philjones is correct - Apache serves the first page that matches the IP address if an IP address is given in the URL.

If a-site.conf, b-site.conf, c-site.conf all have the same IP address specification, then Apache has no way of determining which site to serve.  If you have unique IP addresses, then you can do:

<VirtualHost xxx.xxx.xxx.xxx:80>

where xxx.xxx.xxx.xxx is the unique IP address.  
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

715 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