This document describes how to install an SSL certificate in a Lighthouse instance and enable HTTPS access. The example instance uses an LAMP application image with Apache software pre-installed.
NoteThe SSL certificate used in the document is provided by Tencent Cloud. For more information on this service, see Overview and Purchase Guide.
Name | Description |
---|---|
Lighthouse instance's public IP address | Instance IP address used to connect a local computer to the instance. |
Username | The username used to log in to the Lighthouse instance, such as `root`. |
Password or SSH key | The password matching the username used to log in to the Lighthouse instance, or the bound SSH key. |
NoteYou can log in to the Lighthouse console, find the target instance, and enter its details page to view its public IP address. After the instance is created, first reset the password and remember it, or bind an SSH key and save the private key file. For more information, see Resetting Password and Managing Keys.
cloud.tencent.com
as an example here) to a local directory.1_root_bundle.crt
: Certificate file2_cloud.tencent.com.crt
: Certificate file3_cloud.tencent.com.key
: Private key filecloud.tencent.com.csr
fileNoteYou can upload the CSR file when applying for a certificate or have it generated online by the system. It is provided to the CA and irrelevant to the installation.
ssl
folder.cd /usr/local/lighthouse/softwares/apache
sudo mkdir ssl
Copy the obtained 1_root_bundle.crt
, 2_cloud.tencent.com.crt
, and 3_cloud.tencent.com.key
files from the local directory to the created /usr/local/lighthouse/softwares/apache/ssl
directory. For more information, see Uploading Local Files to Lighthouse.
Run the following command to edit the httpd.conf
configuration file.
sudo vim /usr/local/lighthouse/softwares/apache/conf/httpd.conf
Press i to enter the edit mode and make the following changes:
Delete the #
in #LoadModule ssl_module modules/mod_ssl.so
.
Delete the #
in #LoadModule socache_shmcb_module modules/mod_socache_shmcb.so
.
Replace localhost
in ServerName localhost
with the certificate name. A modified sample is as shown below:
ServerName cloud.tencent.com
Delete the #
in #Include conf/extra/httpd-ssl.conf
.
Press Esc and enter :wq to save the changes.
Run the following command to modify the httpd-ssl.conf
configuration file.
sudo vim /usr/local/lighthouse/softwares/apache/conf/extra/httpd-ssl.conf
Press i to enter the edit mode and make the following changes in <virtualhost _default_:443="">
:
Replace www.example.com:443
in ServerName www.example.com:443
with the certificate name. A modified sample is as shown below:
ServerName cloud.tencent.com
Modify the paths of the certificate files:
SSLCertificateFile "/usr/local/lighthouse/softwares/apache/ssl/2_cloud.tencent.com.crt"
SSLCertificateKeyFile "/usr/local/lighthouse/softwares/apache/ssl/3_cloud.tencent.com.key"
SSLCertificateChainFile "/usr/local/lighthouse/softwares/apache/ssl/1_root_bundle.crt"
Add the following content:
<Directory "/usr/local/lighthouse/softwares/apache/htdocs">
Options Indexes FollowSymLinks
AllowOverride all
Require all granted
</Directory>
Press Esc and enter :wq to save the changes.
Run the following command to restart the Apache service.
sudo /usr/local/lighthouse/softwares/apache/bin/httpd -k restart
After the successful restart, you can use https://cloud.tencent.com
for access as shown below:
You can configure the instance to automatically redirect HTTP requests to HTTPS in the following steps:
Run the following command to edit the httpd.conf
configuration file .
sudo vim /usr/local/lighthouse/softwares/apache/conf/httpd.conf
Press i to enter the edit mode and make the following changes:
#
in #LoadModule rewrite_module modules/mod_rewrite.so
.RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)?$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
The result should be as follows:
3. Press Esc and enter :wq to save the changes.
4. Run the following command to restart the Apache service.
sudo /usr/local/lighthouse/softwares/apache/bin/httpd -k restart
At this point, you have successfully set the automatic redirect to HTTPS. You can use http://cloud.tencent.com
to redirect to the HTTPS page.
Was this page helpful?