Sunday, October 22, 2017

virtualhost - Apache 2 Multiple Named Virtual Hosts with one IP vhost



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



DocumentRoot /var/www/html


DocumentRoot /var/www/html/vh/domain1.com
ServerName domain1.com
DirectoryIndex index.php


DocumentRoot /var/www/html/vh/domain2.com

ServerName domain2.com
DirectoryIndex index.php



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!


Answer



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



NameVirtualHost *:80



to



NameVirtualHost 9.9.9.9:80


or else change each







to






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.


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...