在OpenLiteSpeed服务器上安装SSL证书

Let’s Encrypt提供免费的SSL证书,常见的浏览器,比如Firefox和Chrome,都认可Let’s Encrypt提供的免费SSL证书。

下面介绍如何在Ubuntu 24.04操作系统上,为OpenLiteSpeed服务器安装Let’s Encrypt提供的免费SSL证书。

先安装certbot:

sudo apt-get update
sudo apt-get install certbot

要同时为域名YOUR_DOMAIN www.YOUR_DOMAIN申请证书,可以执行如下命令:

certbot certonly --webroot -w /usr/local/lsws/wordpress/html -d YOUR_DOMAIN -d www.YOUR_DOMAIN

/usr/local/lsws/wordpress/html 替换为你的网站根目录。

如果我们只有一个证书,我们可以在侦听器级别设置它。

访问网址http://yourdomain:7080, 导航到 OpenLiteSpeed > 仪表盘> 侦听器> SSL > SSL 私钥和证书,设置以下值:

私钥文件:/etc/letsencrypt/live/YOUR_DOMAIN/privkey.pem
证书文件:/etc/letsencrypt/live/YOUR_DOMAIN/fullchain.pem
Chained Certificate: yes

导航到 OpenLiteSpeed > 仪表盘> 侦听器> general,设置以下值:

Port: 443
Secure: Yes

单击“保存”,然后执行“平滑重启”:

/usr/local/lsws/bin/lswsctrl restart

至此,SSL证书安装成功!你可以使用https://YOUR_DOMAIN访问你的网站。

了解Let’s Encrypt免费SSL证书的人都知道,证书的有效期只有90天,证书到期后需要续期。关于证书续期的方案,网上有各种各样的教程。一开始,我还在纠结该使用什么方法来实现证书的自动续期。当证书安装完成后,我发现自己想多了,这种证书安装方式默认就实现了自动续期的功能,参见下面的控制台输出:

Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/zhaomihao.com/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/zhaomihao.com/privkey.pem
This certificate expires on 2026-06-05.
These files will be updated when the certificate renews.
Certbot has set up a scheduled task to automatically renew this certificate in the background.

发表评论

您的邮箱地址不会被公开。 必填项已用 * 标注

滚动至顶部