赞
踩
最近安装Caddy在另外一个机器上出现了错误,执行步骤如下:
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy
/etc/caddy/Caddyfile
并配置你的网站,例如:yourdomain.com {
root * /var/www/html
file_server
}
sudo systemctl enable --now caddy
Caddy 默认支持自动 HTTPS 部署,只需确保你的域名解析正确并且服务器开放了 80 和 443 端口。
sudo ufw allow 80
sudo ufw allow 443
sudo ufw allow http
sudo ufw allow https
服务器如果需要配置支持 HTTPS (如果默认不允许),执行如下命令。
sudo ufw allow https
本人在执行 sudo systemctl enable --now caddy 后,命令行并未提示故障,但是实际访问的时候不能正常访问:
执行 journalctl -u caddy.service 观察日志发现:
root@ecs-158006:~# sudo systemctl start caddy
root@ecs-158006:~# sudo systemctl reload caddy
journalctl -u caddy.service
Mar 21 12:07:34 ecs-158006 systemd[1]: Reloading Caddy...
略...
Mar 21 12:07:34 ecs-158006 caddy[2515178]: {"level":"error","ts":1710994054.4442222,"msg":"unable to create folder for config autosave","dir":"/var/lib/caddy/.config/caddy","error":"mkdir /var/lib/caddy: permission denied"}
Mar 21 12:07:34 ecs-158006 caddy[2515178]: {"level":"error","ts":1710994054.444261,"logger":"tls","msg":"job failed","error":"bjkdy.com: obtaining certificate: failed storage check: mkdir /var/lib/caddy: permission denied - storage is probably misconfigured>
Mar 21 12:07:34 ecs-158006 caddy[2515178]: {"level":"info","ts":1710994054.4446912,"logger":"admin.api","msg":"load complete"}
Mar 21 12:07:34 ecs-158006 systemd[1]: Reloaded Caddy.
Mar 21 12:07:34 ecs-158006 caddy[2515178]: {"level":"info","ts":1710994054.4483511,"logger":"admin","msg":"stopped previous server","address":"localhost:2019"}
根据提供的日志信息和配置文件,问题出在Caddy无法创建必要的文件夹来保存证书和配置信息,导致证书管理失败。错误信息显示了权限被拒绝的问题。
为了解决这个问题,尝试以下步骤:
授予Caddy所需的权限:
确保Caddy有足够的权限来创建所需的文件夹。使用以下命令更改文件夹的权限:
sudo chown -R caddy:caddy /var/lib/caddy
重新加载Caddy服务:
在更改了文件夹权限后,重新加载Caddy服务以使更改生效:
sudo systemctl reload caddy
再次尝试访问网站:
https://...
,问题得到解决。通过以上步骤,能够解决Caddy无法创建文件夹的权限问题,从而正常获取和管理SSL证书,使网站能够提供安全连接。希望这些信息对你有帮助。
有的服务器很顺利,有的就不行。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。