前置工作
防火墙放行80和443(Caddy需要80申请证书,443用作HTTPS端口)
UFW (Debian, Ubuntu)
sudo apt install ufw
ufw allow ssh
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable
Firewalld (Centos, AlmaLinux)
sudo dnf install firewalld -y
sudo systemctl enable firewalld
sudo systemctl start firewalld
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --permanent --add-port=443/tcp
sudo firewall-cmd --reload
安装Caddy
Debian, Ubuntu
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
Fedora, RedHat, CentOS, AlmaLinux, RockyLinux
dnf install 'dnf-command(copr)'
dnf copr enable @caddy/caddy
dnf install caddy
设置Caddy开启启动和启动Caddy
sudo systemctl enable caddy
sudo systemctl start caddy
编辑Caddyfile文件
Vi编辑CaddyFile文件
sudo vi /etc/caddy/Caddyfile
按i之后,使用 Ctrl+Shift+V 粘贴代码。
粘贴完后,使用 Esc ,然后使用 :wq 保存退出。
反代代码
your.domain.com { # 这里写你用的域名
reverse_proxy https://target.domain:443 { # 这里写反代的域名
header_up Host {upstream_hostport}
}
}
重启Caddy
sudo systemctl restart caddy
Caddy会自动申请证书,然后反代目标Emby网站。