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 website.
Configurate the <VirtualHost> file block for the site. Refer to <VirtualHost *:80> to create a VirtualHost for 443, and add the following code.
<VirtualHost *:443>
SSLEngine on
SSLCertificateFile /path/to/your_domain_name.crt
SSLCertificateKeyFile /path/to/your_private.key
</VirtualHost>
3 Enable ssl module
For CentOS server, use "httpd -M | grep ssl" to check if the SSL module is installed. If it’s not, install it through "yum install mod_ssl ".
For Ubuntu server, use "apache2 -M | grep ssl" to check if the SSL module is installed. If it’s not, install it through "apt install mod_ssl ".
4 Test your Apache configuration file
For CentOS and Ubuntu server, please run "apachectl configtest". If "Syntax OK" is displayed, the configuration file setup was successful.
5 Restart Apache
For CentOS server, restart the Apache Service by using " systemctl restart httpd ".
For Ubuntu server, restart the Apache Service by using " systemctl restart apache2 ".
6 Test the HTTPs of your website
7 Add redirection from HTTP to HTTPS
7.1 Install redirect module
For CentOS server, please refer to the following:
For Ubuntu server, please refer to the following:
apt 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.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
8 Restart Apache
For CentOS server, restart the Apache Service by using " systemctl restart httpd ".
For Ubuntu server, restart the Apache Service by using " systemctl restart apache2 ".