在Ubuntu 16.04上,使用Lighttpd安装let\'s Encrypt
Anne655
・4 分钟阅读
介绍
let's Encrypt是颁发免费SSL/TLS证书的证书颁发机构(CA ),Lighttpd是一个轻量级的web服务器,只需要低资源就可以运行,
先决条件
本教程假设你已经创建了云计算实例,有指向服务器的域名,并已作为root登录。
第一步:安装Certbot
第一步是安装Certbot,添加Certbot存储库提示确认时按Enter
。
add-apt-repository ppa:certbot/certbot
安装Certbot
apt-get update
apt-get install certbot
步骤2:获取SSL证书
安装Certbot后你可以获得SSL证书,运行以下命令,将example.com
替换为你自己的域名:
certbot certonly --webroot -w /var/www/html -d example.com -d www.example.com
继续使用交互式安装程序。
步骤3:为Lighttpd使用的安装证书文件
Certbot将获取的证书文件放在/etc/letsencrypt/live/example.com
中,你将需要授权Lighttpd用户访问这个目录。
chown $1-data /etc/letsencrypt
chown $1-data /etc/letsencrypt/live
chmod g+x /etc/letsencrypt
chmod g+x /etc/letsencrypt/live
Lighttpd要求证书和私钥在单个文件中,你需要把这两个文件组合起来,运行以下命令,用你自己的域名替换example.com
。
cat /etc/letsencrypt/live/example.com/privkey.pem /etc/letsencrypt/live/example.com/cert.pem > /etc/letsencrypt/live/example.com/merged.pem
privkey.pem
和cert.pem
文件将被合并并保存为merged.pem
。
步骤4:配置Lighttpd
一旦证书文件就绪,就可以继续,并且配置Lighttpd以便使用SSL证书,打开Lighttpd配置文件进行编辑。
nano /etc/lighttpd/lighttpd.conf
在文件末尾添加以下块,用你自己的域名替换example.com
,
$SERVER["socket"] ==":443" {
ssl.engine ="enable"
ssl.ca-file ="/etc/letsencrypt/live/example.com/chain.pem"
ssl.pemfile ="/etc/letsencrypt/live/example.com/merged.pem"
}
步骤5:强制SSL使用
为了增加安全性,你可以强制Lighttpd服务器将所有HTTP请求路由到HTTPS ,打开lighttpd.conf
文件进行编辑。
nano /etc/lighttpd/lighttpd.conf
在文件的末尾添加以下块,
$HTTP["scheme"] =="http" {
$HTTP["host"] =~".*" {
url.redirect = (".*" =>"https://%0$0")
}
}
你需要重启Lighttpd服务器以便让更改生效。
systemctl restart lighttpd
更新SSL证书
Let's Encrypt颁发有效期为90天的SSL证书,在证书过期前,你将需要续订你的证书以避免证书错误,你可以使用Certbot续订证书。
certbot renew
你需要将Lighttpd的证书和私钥组合在一起。运行以下命令,用你的域名替换example.com
。
cat /etc/letsencrypt/live/example.com/privkey.pem /etc/letsencrypt/live/example.com/cert.pem > /etc/letsencrypt/live/example.com/merged.pem
你的证书将延期90天