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).
1 Upload the .key and .crt files
Upload the .key and .crt files to your Linux Server.
2 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--------------------
3 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 ".
4 Test your Apache configuration file
Please run "apachectl configtest". If "Syntax OK" is displayed, the configuration file setup was successful.
5 Restart Apache
Restart the Apache Service using " apachectl restart ".
6 Test the HTTPs of your website
7 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--------------------
8 Restart Apache
Restart the Apache Service using " apachectl restart ".