Situation:
I have two Drupal / PHP websites / applications
https://qa.example.com/app1
https://qa.example.com/app2
I wanted to setup Apache2 to listen for SSL connection on port 9443 and need to have 2 seperate virtual host files or site files under “sites-available” folder in Apache2.
I created something like this for each
<IfModule mod_ssl.c>
<VirtualHost *:9443>
ServerName qa.example.com
ServerAdmin webmaster@server
Alias /app1 /var/www/html/qa/app1
DocumentRoot “/var/www/html/qa/app1”
# Available loglevels: trace8, …, trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/app1-ssl-qa-error.log
CustomLog ${APACHE_LOG_DIR}/app1-ssl-qa-access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with “a2disconf”.
#Include conf-available/serve-cgi-bin.conf
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/ssl/certs/example.pem
SSLCertificateKeyFile /etc/ssl/private/example.key
<FilesMatch “\.(cgi|shtml|phtml|php)$”>
SSLOptions +StdEnvVars
</FilesMatch>
# <Directory /usr/lib/cgi-bin>
<Directory “/var/www/html/qa/app1”>
SSLOptions +StdEnvVars
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
</VirtualHost>
</IfModule>
The issue:
I need Apache to load App1 when app1 url is accessed and app2 when app2 url is accessed. But when setting up the two apps with seperate virtual host files like above, accessing the apps using either urls only loaded the first virtual host listed in Apache.
The Fix:
I had to merge the two aliases to one virtual hosts file like below to make it work how I want.
<IfModule mod_ssl.c>
<VirtualHost *:9443>
ServerName qa.example.com
ServerAdmin webmaster@server
Alias /app1 /var/www/html/qa/app1
DocumentRoot “/var/www/html/qa/app1”
Alias /app2 /var/www/html/qa/app2
DocumentRoot “/var/www/html/qa/app2”
# Available loglevels: trace8, …, trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/app1-ssl-qa-error.log
CustomLog ${APACHE_LOG_DIR}/app1-ssl-qa-access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with “a2disconf”.
#Include conf-available/serve-cgi-bin.conf
# SSL Engine Switch:
# Enable/Disable SSL for this virtual host.
SSLEngine on
# A self-signed (snakeoil) certificate can be created by installing
# the ssl-cert package. See
# /usr/share/doc/apache2/README.Debian.gz for more info.
# If both key and certificate are stored in the same file, only the
# SSLCertificateFile directive is needed.
SSLCertificateFile /etc/ssl/certs/example.pem
SSLCertificateKeyFile /etc/ssl/private/example.key
<FilesMatch “\.(cgi|shtml|phtml|php)$”>
SSLOptions +StdEnvVars
</FilesMatch>
# <Directory /usr/lib/cgi-bin>
<Directory “/var/www/html/qa/app1“>
SSLOptions +StdEnvVars
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
<Directory “/var/www/html/qa/app2“>
SSLOptions +StdEnvVars
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
</VirtualHost>
</IfModule>
This way the problem is that we cannot disable one app and keep the other enabled. If anyone knows a solution for this please let me know.