Set up an Apache SSL Virtual Host

Posted by Morgan Billingsley on December 30, 2019 7:20 pm

Enabling a virtual host on port 443 with a signed, ssl certificate allows users to access your website in a secure fashion.

Follow the steps below to enable your Apache virtual host with SSL.

Step 1: Create the configuration file

If you already have a configuration file for your domain’s connection on port 80, you can append the ssl virtual host configuration to that file; otherwise, you need to create an apache virtual host configuration file:

sudo nano /etc/apache2/sites-available/

Step 2: Add the configuration settings to the file

Make sure you have enabled the Apache ssl module for your server. You can check if it is enabled by entering the following command in your command line:

sudo apache2ctl -M | grep ssl

If the ssl module is enabled, the above command will return ssl_module (shared). If nothing is returned from the command above, visit my post on enabling the apache ssl module

Once you have verified that the ssl module is installed, use the following configuration settings to set up your own virtual host for port 443:

<VirtualHost *:443>
    DocumentRoot /var/www/html/example/public
    SSLEngine On
    SSLCertificateFile "/etc/ssl/"
    SSLCertificateKeyFile "/etc/ssl/"
    ErrorLog ${APACHE_LOG_DIR}/example-error.log
    CustomLog ${APACHE_LOG_DIR}/example-access.log combined