<VirtualHost *:8080>
    # Configure ServerAdmin and ServerName
    ServerName localhost
    ServerAdmin webmaster@localhost

    # Set CloudFlare Real IP
    RemoteIPHeader CF-Connecting-IP

    # Turn on rewrite engine
    RewriteEngine On
    
    # Redirect traffic from localhost to https://localhost:8443
    RewriteCond %{SERVER_NAME} =localhost
    RewriteRule ^ https://%{SERVER_NAME}:8443%{REQUEST_URI} [END,NE,R=permanent]

    # Redirect all other traffic to https://host:443
    RewriteCond %{SERVER_NAME} !=localhost
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

    # Configure Log Settings
    LogFormat "%l %u %t %v %a \"%r\" %>s %b" comonvhost
    ErrorLog /dev/stderr
    TransferLog /dev/stdout
    LogLevel ${LOG_OUTPUT_LEVEL}

</VirtualHost>

<VirtualHost *:8443>
    Include /etc/apache2/vhost-templates/https.conf
</VirtualHost>