如果你开启了自动获取https证书,那么80端口就一定会被caddy占用,因为这是用来从let's encryt申请证书用的,其实获取完毕后端口就不需要占用了,但是caddy还是会一直占着,解决办法就是手动输入密钥。

手动申请免费证书

进行前请务必保证80端口没有被占用,不然会验证失败。

git clone https://github.com/letsencrypt/letsencrypt
cd letsencrypt
./letsencrypt-auto certonly --standalone --email [email protected] -d website.com -d www.website.com

这里的[email protected]是你的邮箱,website.com是你域名

完成后,证书文件会生成在/etc/letsencrypt/live/{你的域名}/目录下

这是caddy配置文件,笔者将证书文件放在了root下

www.website.com:443 {
    tls /root/encrypt/fullchain.pem /root/encrypt/privkey.pem
    timeouts none
}

最后重启caddy

sudo systemctl restart caddy.service

letsencrypt续期

./letsencrypt-auto certonly --renew-by-default --email [email protected] -d website.com -d www.website.com