Install an SSL Certificate on an Apache2 Server
By installing an SSL certificate on your Apache server, you can enable HTTPS secure access for the server. This document describes how to install an SSL certificate on an Apache server.
This document uses Apache version Apache/2.4.58(ubuntu) as an example.
Before installation, confirm that 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 file in .zip compressed format. The compressed package contains four folders corresponding to four certificate formats: Tomcat, Nginx, IIS, and Apache. Apache servers require the certificate files in the Apache folder.
- The Apache folder contains 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/apache2/ssldirectory on the Apache server. Note:
- If the
/etc/apache2/ssldirectory does not exist, you can create it with themkdir -p /etc/apache2/sslcommand - There may be differences between different versions; some Apache directories may be
/etc/httpd
- Since Apache only reads configuration files from
sites-enabled, you need to create a symbolic link.
ln -s /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/000-default-ssl.conf
- Edit the
/etc/apache2/sites-available/default-ssl.conffile and modify the following content:
<VirtualHost *:443>
DocumentRoot /var/www/html
#启用 SSL 功能
SSLEngine on
#证书文件的路径
SSLCertificateFile /etc/apache2/ssl/domain_com.crt
#私钥文件的路径
SSLCertificateKeyFile /etc/apache2/ssl/domain_com.key
#证书链文件的路径
SSLCertificateChainFile /etc/apache2/ssl/domain_com.ca-bundle
</VirtualHost>
After making the modifications, save the configuration file and run the following command:
a2enmod ssl #加载ssl模块,如果是替换证书可以忽略
apache2ctl configtest #检测配置文件是否报错
apache2ctl restart #重启Apache使配置生效
Testing 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 the installation is successful, a security padlock icon will appear in the browser address bar; click it to view certificate information.

Security configuration for automatic HTTP-to-HTTPS redirection (optional)
If you need to automatically redirect HTTP requests to HTTPS, you can configure it with the following steps:
- Enter
a2enmod rewritein the command line to enable the redirection module - Then open the HTTP configuration file, for example:
/etc/apache2/sites-available/000-default.conf, 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, and you will then be able to access the website via the domain name, with automatic redirection from HTTP to HTTPS implemented.