HostOnNet Blog

Enable SSL in Apache VirtualHost

Looking for Linux Server Admin or WordPress Expert? We can help.

To enable SSL in for a web site in Apache, you need to copy the non SSL virtual host entry and make a new entry for SSL enabled Virtual Host.

Let says we have a virtual host entry like following.

<VirtualHost *:80>
    DocumentRoot "/home/hostonnet.com/public"
    ServerName www.hostonnet.com
    ServerAlias hostonnet.com

    <Directory "/home/hostonnet.com/public">
        Options All
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Find

<VirtualHost *:80>

Replace with

<VirtualHost *:443>

Inside virtual host entry, add

SSLEngine on
SSLCertificateFile /etc/apache2/ssl/hostonnet.com.crt
SSLCertificateKeyFile /etc/apache2/ssl/hostonnet.com.key
SSLCACertificateFile /etc/apache2/ssl/hostonnet.com.ca

Replace with to .crt, .key and .ca files with your own SSl certificate location.

New VirtualHost entry will look like

<VirtualHost *:443>
    DocumentRoot "/home/hostonnet.com/public"
    ServerName www.hostonnet.com
    ServerAlias hostonnet.com

    SSLEngine on
    SSLCertificateFile /etc/apache2/ssl/hostonnet.com.crt
    SSLCertificateKeyFile /etc/apache2/ssl/hostonnet.com.key
    SSLCACertificateFile /etc/apache2/ssl/hostonnet.com.ca

    <Directory "/home/hostonnet.com/public">
        Options All
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Ubuntu – Enable mod_ssl

To enable mod_ssl in Ubuntu, run

a2enmod ssl
service apache2 restart

If you are on Ubuntu, save the virtual host entry as

vi /etc/apache2/sites-available/YOURDOMAIN.EXTN-ssl.conf

Now activate the site with

a2ensite YOURDOMAIN.EXTN-ssl
service apache2 restart

See also Enable SSL in Nginx and SSL

Posted in Security

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.