How to install SSL certificate on web server hosted in Linux

In this article we will shows step-by-step instructions on How to install SSL certificate on web server hosted in Linux operating system.

In one of the previous post we have already generated the self-signed SSL cert so I would request you to visit it on getting the CERT How to Generate Self-Signed Certificate on Rocky Linux.

Pre-requisite

Packages Installation

Let us install the required packages

dnf -y install mod_ssl

Allow Firewall for HTTPS

firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --reload

Configuring the SSL/TLS Settings

Open the default configuration file

vi /etc/httpd/conf.d/ssl.conf

Change the following Lines

FROM

SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key

TO

SSLCertificateFile /etc/pki/tls/certs/server.crt
SSLCertificateKeyFile /etc/pki/tls/private/server.csr

To redirect all HTTP traffic to HTTPS

Create a new file

vi /etc/httpd/conf.d/redirect_http.conf

Insert the following content and save file, replacing “your-server-hostname” with your hostname

<VirtualHost _default_:80>
    Servername rocky-linux
    Redirect permanent / https://your-server-hostname-or-ip/
</VirtualHost/>

Enable and restart the HTTP service

systemctl enable httpd
systemctl restart httpd

The Apache web server will redirect any incoming traffic from http://your-server-hostname to https://your-server-hostname 

Test the mod_ssl configuration

Enter the following in a web browser:

https://your-server-ip

OR

https://your-server-hostname

Conclusion

We hope that this post has made it clearer for you to understand how to use SSL to secure Apache on Rocky Linux. If you need more information on the usage of SSL for Rocky Linux you may refer mod_ssl on Rocky Linux

Leave a comment