How to Apply an SSL on Apache

Introduction

In this article, we will guide you through the steps of installing an SSL certificate on the Apache web server in the CentOS/Ubuntu Operation System.
 
We assume that you have Apache installed on your server and have certificate files(including .key and .crt files).
 

Upload the .key and .crt files

Upload the .key and .crt files to your Linux Server.
 

Configure the <VirtualHost> block

Open the configuration file of the virtual host. The path to the configuration file is usually as follows:
/etc/httpd/conf/sites-enabled/your_domain_name.vhost
 
Configurate the <VirtualHost> file block for the site. Refer to <VirtualHost *:80> to create a VirtualHost for 443, and add the following code.
---------------------------------begin of script------------------
<VirtualHost *:443>
        SSLEngine on
        SSLCertificateFile /path/to/your_domain_name.crt
        SSLCertificateKeyFile /path/to/your_private.key
</VirtualHost>
---------------------------------end of script--------------------
 

Enable ssl module  

Use "httpd -M | grep ssl" to check if the SSL module is installed. If it’s not, install it through " install mod_ssl ".
 

Test your Apache configuration file

Please run "apachectl configtest". If "Syntax OK" is displayed, the configuration file setup was successful.
 

Restart Apache 

Restart the Apache Service using " apachectl restart ".
 

Test the HTTPs of your website

You can access your website via https://your_domain_name now.
 

Add redirection from HTTP to HTTPS

7.1 Install redirect module

yum install mod_rewrite
 

7.2 Edit configuration file

Modify the “/etc/httpd/conf/httpd.conf” file and add the following at the end of the file.
---------------------------------begin of script------------------
RewriteEngine On
RewriteCond %{HTTPS} off
---------------------------------end of script--------------------
 

Restart Apache 

Restart the Apache Service using " apachectl restart ".

Add Feedback