Here are my requirements:
- Host multiple sites on same server. Some sites use SSL others do not.(port 443 and 80)
- If the domains don’t match then return a 403 or custom response
The server is a LAMP stack with Ubuntu using Apache 2.4+.
Currently my configuration is not working properly. I’ve added the default VirtualHost but if I browse to a domain not on the server in HTTPS (https://thisisnotasite.com) it will offer me the ability to procced to the site I want it to go to 403 instead.
And if I add a * instead of port 80 to the default-403.conf
, it will always load the actual site. With port 80 all HTTP requests are redirected to 403. However if I add a site that is not SSL the system will always go there.
In my apache.conf
file I have changed the import line for virtual host to each file so I have control over load sequence. (snippets below)
#Include the virtual host configurations:
IncludeOptional sites-enabled/default-403.conf
IncludeOptional sites-enabled/Site1.conf
IncludeOptional sites-enabled/SSLSite2.conf
IncludeOptional sites-enabled/SSLSite3.conf
IncludeOptional sites-enabled/Site4.conf
Default-403.conf
<VirtualHost *:80>
ServerAdmin Admin@admin.com
ServerName catchAll
Redirect 403 /
UseCanonicalName Off
ErrorLog ${APACHE_LOG_DIR}/catchAllError.log
CustomLog ${APACHE_LOG_DIR}/catchAll.log combined
</VirtualHost>
Site1.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName site1.com
ServerAlias www.site1.com
Redirect permanent "/" "https://www.site3.com/"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
SSLSite2 (this is an old site and site3 is the new one)
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin Admin@admin.com
ServerName site2.com
ServerAlias www.site2.com
Redirect permanent "www.site2.com" "https://www.site3.com/"
Redirect permanent "site2.com" "https://www.site3.com/"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/site2.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/site2.cert
SSLCertificateKeyFile /etc/ssl/private/site2.key
SSLCertificateChainFile /etc/ssl/certs/site2.csr
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
</VirtualHost>
</IfModule>
SSLSite3
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin@admin.com
ServerName site3.com
ServerAlias www.site3.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/site3.crt
SSLCertificateKeyFile /etc/ssl/private/site3.key
SSLCertificateChainFile /etc/ssl/certs/sit3.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
BrowserMatch "MSIE [2-6]" \
nokeepalive ssl-unclean-shutdown \
downgrade-1.0 force-response-1.0
</VirtualHost>
</IfModule>
Site4.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName site4.com
ServerAlias www.site4.com
DocumentRoot /var/www/site2
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
As of right not site1 and site2 redirect to site3 and if I add import for site 4 then every request gets send to site4. If I change default-403 to have a * instead of port 80 then everything goes to site4.
Any help will be greatly appreciated.
Please note I've only been exposed to Apache for about 2 months so if there is a much better way to handle this please let me know.