Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an instance running on AWS, with an Apache 2, two named domains and one ip.

I managed to configure apache with both domains, ( domain1.com and domain2.com ). The first domain's docroot is pointing to /var/www/html/vh/domain1.com The second domain's docroot is pointing to /var/www/html/vh/domain2.com

This is ok.

The problem is, that I want to access /var/www/html using IP directly on the browser.

When I try to do that, I get the site hosted on domain1.com .

How can I do that??

Relevant lines from httpd.conf:

ServerName 9.9.9.9:80
DocumentRoot "/var/www/html"

NameVirtualHost *:80

<VirtualHost 9.9.9.9:80>
    DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost 9.9.9.9:80>
    DocumentRoot /var/www/html/vh/domain1.com
    ServerName domain1.com
    DirectoryIndex index.php
</VirtualHost>
<VirtualHost 9.9.9.9:80>
    DocumentRoot /var/www/html/vh/domain2.com
    ServerName domain2.com
    DirectoryIndex index.php
</VirtualHost>

If I try to access :

http://9.9.9.9

I get the pages under /var/www/html/vh/domain1.com instead of the pages hosted at /var/www/html

What am I doing wrong?

Thx in advance!

share|improve this question

2 Answers 2

up vote 2 down vote accepted

Your NameVirtualHost and <VirtualHost> directives must match. This means that you must either change

NameVirtualHost *:80

to

NameVirtualHost 9.9.9.9:80

or else change each

<VirtualHost 9.9.9.9:80>

to

<VirtualHost *:80>

Also, I would recommend that the default virtualhost have the actual hostname of the server as ServerName, instead of the IP address. Since it will be default, it'll still be the one chosen when you connect using only the IP address.

share|improve this answer

You can check how apache interprets your config with the command apache2ctl -S. It lists all the vhosts and their order as they are currently used by apache. When accessing the server with the IP address the default server from that list will be used. You may have other vhost configurations loaded that are used.

Also the ServerName should be the fully qualified domain name of you server and not the IP address. To see the current fully qualified domain name use hostname --fqdn.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.