Configuring SSL site in Ubuntu Server

Create file

vi /etc/apache2/sites-available/YOUR-DOMAIN.EXTN-ssl.conf

Add following content

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
    ServerName YOUR-DOMAIN.EXTN
    ServerAlias www.YOUR-DOMAIN.EXTN
    ServerAdmin admin@YOUR-DOMAIN.EXTN
    DocumentRoot /home/YOUR-DOMAIN.EXTN/public_html/

    CustomLog ${APACHE_LOG_DIR}/YOUR-DOMAIN.EXTN-ssl.log combined
    ErrorLog ${APACHE_LOG_DIR}/error-YOUR-DOMAIN.EXTN-ssl.log
    
    SSLEngine on
    SSLCertificateFile  /etc/ssl/certs/YOUR-DOMAIN.EXTN.crt
    SSLCertificateKeyFile /etc/ssl/private/YOUR-DOMAIN.EXTN.key
    SSLCACertificateFile /etc/apache2/ssl.crt/YOUR-DOMAIN.EXTN.ca-bundle

    <Directory "/home/YOUR-DOMAIN.EXTN/public_html/">
        Options All
        AllowOverride All
        Require all granted
        Order allow,deny
        allow from all
    </Directory>

</VirtualHost>
</IfModule>

Enable the web site

a2ensite YOUR-DOMAIN.EXTN-ssl

Enable Apache SSL module if not already enabled

a2enmod ssl

Restart Apache

service apache2 restart

You can verify SSL module enabled by running

root@ip-172-31-32-78:~# apachectl -M | grep ssl
 ssl_module (shared)
root@ip-172-31-32-78:~# 

Now web site will work with SSL certificate.


Posted in Apache