Setting Up Apache Config File and SSL Certificate for Multi Domain and Subdomain Usage on Same Server
Setting Up Apache Config File and SSL Certificate for Multi Domain and Subdomain Usage on Same Server
Jason Jason Photo By Jason Jason, Feb 04, 2016

I use the same physical server for a lot of different websites that each need their own webapp, directory structure, configuration options, SSL certificate, etc. Of course, the easy way to do all this would be to setup each webapp on its own virtual server, such as digitalocean.com. This is often the best route is you just need a simple server to develop on, or you just have one or two websites. But when you have a lot of websites that you maintain, this can get a little pricey. So I've developed a system to get a new webapp up and running with its own settings.

<VirtualHost *:80>
    ServerAdmin jj@bakerstreetsystems.com
    ServerName bakerstreetsystems.com
    ServerAlias www.bakerstreetsystems.com

    <Directory "/var/www/bakerstreetsystems/www.bakerstreetsystems.com/octobercms">
        Options FollowSymLinks
        AllowOverride All
    </Directory>

    DocumentRoot /var/www/bakerstreetsystems/www.bakerstreetsystems.com/octobercms
</VirtualHost>

<IfModule mod_ssl.c>
    <VirtualHost *:443>
        ServerAdmin jj@bakerstreetsystems.com
        ServerName bakerstreetsystems.com
        ServerAlias www.bakerstreetsystems.com

        <Directory "/var/www/bakerstreetsystems/bakerstreetsystems.com/">
            Options FollowSymLinks
            AllowOverride All
        </Directory>

        DocumentRoot /var/www/bakerstreetsystems/bakerstreetsystems.com/

        # Guarantee HTTPS for 2 Years including Sub Domains
        Header always set Strict-Transport-Security "max-age=63072000; includeSubdomains; preload"

        SSLEngine on
        SSLCertificateFile /etc/apache2/ssl/www.bakerstreetsystems.com.crt
        SSLCertificateKeyFile /etc/apache2/ssl/www.bakerstreetsystems.com.key
        SSLCertificateChainFile /etc/apache2/ssl/www.bakerstreetsystems.com-intermediate.crt

    </VirtualHost>
</IfModule>

Reference:

How To Set Up Apache Virtual Hosts on Ubuntu 14.04 LTS

How To Secure Apache with Let's Encrypt on Ubuntu 14.04


Tags & Categories

Apache SSL