I want to host two different angular panels over Apache (AWS). So I disabled the default 000-default.conf file in etc/apache2/sites-available using a2dissite 000-default.conf and made two files webAdmin.conf and webUIpanel.conf. Now my webAdmin.conf has the following configuration
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/AngularProjects/getItHomeNow_UI/dist
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and webUIpanel.conf has following
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/AngularProjects/getItHomeNow_UserPanel/dist
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then I used a2ensite to enable both config files and at last sudo systemctl restart apache2. But one of them working at a time. I need to disable one to make other work. Kindly suggest me where did I go wrong?
You should add ServerName in your VirtualHost config so Apache can decide which site should get the request. So to apply that to your config it should look like:
webAdmin.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/AngularProjects/getItHomeNow_UI/dist
ServerName www.example1.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
and webUIpanel.conf has following
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/AngularProjects/getItHomeNow_UserPanel/dist
ServerName www.example2.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
NOTE: Both ServerName should be valid domains so they resolve to your server or use your /etc/hosts file to point them to your server IP.