1. 下载文件
wget -O caddy "https://caddyserver.com/api/download?os=linux&arch=amd64"
2. 修改权限
chmod a+x caddy
3. 添加用户和组
sudo groupadd --system caddy
sudo useradd --system --gid caddy --create-home --home-dir /var/lib/caddy --shell /usr/sbin/nologin --comment "Caddy web server" caddy
4. 设置caddy服务
创建一个systemd服务文件/etc/systemd/system/caddy.servic
[Unit]
Description=Caddy web server
After=network.target
[Service]
User=caddy
Group=caddy
ExecStart=/usr/local/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/local/bin/caddy reload --config /etc/caddy/Caddyfile
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
5. 启动caddy
sudo systemctl daemon-reload
sudo systemctl enable caddy
sudo systemctl start caddy
6. 检查caddy状态
sudo systemctl status caddy