Install an SSL Certificate on Apache Server
You can enable HTTPS secure access to your Apache server by installing an SSL certificate on it. This article describes how to install an SSL certificate on an Apache server.
This document uses Apache version Apache/2.4.6 as an example.
Before installation, make sure port 443 is not occupied. If port 443 is already in use, bind another port when installing the certificate.
Obtain the Certificate
- After we issue the certificate for you, we will provide the certificate files in a compressed package (.zip). The package contains four folders corresponding to four certificate formats: Tomcat, Nginx, IIS, and Apache; the Apache server requires the certificates in the Apache folder.
- The Apache folder will contain three files:
domain_com.crtcertificate filedomain_com.keyprivate key filedomain_com.ca-bundlecertificate chain file
Install the SSL Certificate
- Copy the obtained
domain_com.crtcertificate file,domain_com.keyprivate key file, anddomain_com.ca-bundlecertificate chain file from your local directory to the/etc/httpd/ssldirectory on the Apache server.
- If the
/etc/httpd/ssldirectory does not exist, you can create it using themkdir -p /etc/httpd/sslcommand - Differences may exist between versions; the Apache directory may be
/etc/apache2in some cases
- Check the
httpd.confconfiguration file in the/etc/httpd/confdirectory, locate theInclude conf.modules.d/*.confconfiguration directive, and confirm that this directive is not commented out. If it is already commented out, remove the comment symbol (#) at the beginning of the line and save the configuration file. - Check the
00-ssl.confconfiguration file in the/etc/httpd/conf.modules.ddirectory, locate theLoadModule ssl_module modules/mod_ssl.soconfiguration directive, and confirm that this directive is not commented out. If it is already commented out, remove the leading comment symbol (#) and save the configuration file.
If LoadModule ssl_module modules/mod_ssl.so is not found in the above configuration file, please confirm whether the mod_ssl.so module has been installed. If the mod_ssl.so module is not installed, you can install it by running the yum install mod_ssl command.
- Edit the
ssl.confconfiguration file under the/etc/httpd/conf.ddirectory. Modify the following content:
<VirtualHost *:443>
DocumentRoot /var/www/html
#启用 SSL 功能
SSLEngine on
#证书文件的路径
SSLCertificateFile /etc/httpd/ssl/domain_com.crt
#私钥文件的路径
SSLCertificateKeyFile /etc/httpd/ssl/domain_com.key
#证书链文件的路径
SSLCertificateChainFile /etc/httpd/ssl/domain_com.ca-bundle
</VirtualHost>
- Restart the Apache server after saving the configuration file.
Test the SSL certificate
Enter the domain name bound with the SSL certificate in the browser address bar to test whether your SSL certificate is installed successfully. If successful, a security padlock icon will appear in the browser address bar, and you can click it to view certificate information.

Security configuration for automatic HTTP to HTTPS redirect (optional)
If you need to automatically redirect HTTP requests to HTTPS, you can configure it with the following steps:
- Edit the
httpd.confconfiguration file in the/etc/httpd/confdirectory. Check whetherLoadModule rewrite_module modules/mod_rewrite.soexists in the configuration file. If it exists, remove the leading comment symbol (#); if it does not exist, add the lineLoadModule rewrite_module modules/mod_rewrite.so, then save the configuration file. - Open the http.conf file and add the following content to the configuration file:
<VirtualHost *:80>
# 新增
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
</VirtualHost>
- Restart the Apache server to access via the domain name and enable automatic redirection from HTTP to HTTPS.