安装caddy

pacman -S caddy

Debian安装

apt install -y debian-keyring debian-archive-keyring apt-transport-https
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' |  tee /etc/apt/sources.list.d/caddy-stable.list
apt update
apt install caddy

添加 http.handlers.replace_response模块

caddy add-package github.com/caddyserver/replace-response

检查http.handlers.replace_response模块是否安装完成

[root@archlinux ~]# caddy list-modules | grep http.handlers.replace_response
http.handlers.replace_response

Caddy目录

[root@archlinux caddy]# tree
.
├── Caddyfile
└── conf.d

修改默认 Caddyfile配置文件 注册 replace指令

nano /etc/caddy/Caddyfile
{
    order replace after encode
}

添加网站配置

nano /etc/caddy/conf.d/example.com
example.com {
  reverse_proxy https://example.com {
  header_up Host {upstream_hostport}
  header_up Accept-Encoding identity
  }
  replace aaa bbb
}

重载caddy配置

systemctl reload caddy

参考

https://caddyserver.com/docs/caddyfile/directives/reverse_proxy

https://github.com/caddyserver/replace-response

Last modification:November 30, 2023
如果觉得我的文章对你有用,麻烦点个赞吧 !