sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
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
sample.caddy.com {
reverse_proxy 127.0.0.1:8080
}
等效 nginx 配置
http {
upstream sample.caddy.com {
server 127.0.0.1:8080;
}
server {
listen 80;
server_name sample.caddy.com;
location / {
proxy_pass http://sample.caddy.com;
proxy_set_header Host $host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
server {
listen 443;
server_name sample.caddy.com;
# 省略 ssl 等配置一大堆
}
}
# 启动
systemctl enable --now caddy
# 查看状态
systemctl status caddy
# 重载配置文件
systemctl reload caddy
# 停止
systemctl stop caddy