Sunday, November 2, 2014

ubuntu - Only one Apache virtualhost configuration comes into effect



I'm using Apache 2.4 on an installation of Ubuntu 14.04, and I'm in the process of configuring Apache "virtualhosts" in order to be able to serve different content for different hostnames.



I'm trying to configure Apache such that when one tries to access the server with the hostname (www.)example1.com, content from /var/www/example1 is served; however, if one tries to access the server with it's IP address, or any other hostname except for (www.)example1.com (for example, via directly accessing it through the IP, or through any other hostname pointing at this IP) content from /var/www/html is served instead.



I have the following configuration files under /etc/apache2/sites-available:



/etc/apache2/sites-available/example1.conf:





DocumentRoot /var/www/example1
ServerAlias www.example1.com
ErrorLog ${APACHE_LOG_DIR}/ex1_error.log
CustomLog ${APACHE_LOG_DIR}/ex1_access.log combined



/etc/apache2/sites-available/000-default.conf:





DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined



However, when I try to access the website by direct access or through the other hostnames pointing at this IP, I get the content served from /var/www/example1 and not from /var/www/html.




What could be the issue here, and how can I fix it?


Answer



On 2.4 use _default_:




DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined



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...