Contents
使用官方工具生成
https://caddyserver.com/download
优点是比较方便,缺点是无法添加未收录的第三方插件。
使用 xcaddy 编译
前提:安装了 Golang,并设置好PATH变量。这方面不是本文的重点,暂时略过。
#下载编译用工具xcaddy:
go install github.com/caddyserver/xcaddy/cmd/xcaddy@master
# caddy2能用的forwardproxy插件:
git clone -b naive https://github.com/klzgrad/forwardproxy
## 编译 Caddy2:
xcaddy build \
--with github.com/abiosoft/caddy-exec \
--with github.com/caddyserver/forwardproxy=$PWD/forwardproxy \
--with github.com/imgk/caddy-trojan \
--with github.com/mholt/caddy-webdav \
--with github.com/caddy-dns/cloudflare
## 交叉编译widows版,并指定版本号(尝试测试版之类)
export GOARCH=386 GOOS=windows
xcaddy build v2.5.2 \
--with github.com/abiosoft/caddy-exec \
--with github.com/caddyserver/forwardproxy=$PWD/forwardproxy \
--with github.com/imgk/caddy-trojan \
--with github.com/mholt/caddy-webdav \
--with github.com/caddy-dns/cloudflare \
--output ./caddy.exe
说明
1、需要网络保持畅通,请各显神通。
2、默认编译latest版,也可以指定特定版本。
3、查看Caddy版本号: https://github.com/caddyserver/caddy/releases
4、虽然Caddy2不如Caddy1简单,但是毕竟现在只更新2,早迁移早安心。
Caddy2配置
{
##全局选项,必须放在前面
order webdav before file_server
#order forward_proxy before reverse_proxy
#开启实验性HTTP/3
experimental_http3
##可以像这样加注释
#email [email protected]
# nano /etc/hosts
# 127.0.0.1 localhost localhost
#caddy2测试:
#caddy run -config Caddyfile.conf
#caddy2运行(如果不以Caddyfile打头,则需要加 --adapter caddyfile):
#caddy start -config Caddyfile.conf --adapter caddyfile
}
(theheaders) {
# header_up Host {http.reverse_proxy.upstream.hostport}
header_up X-Real-IP {http.request.remote}
header_up X-Forwarded-For {http.request.remote}
header_up X-Forwarded-Port {http.request.port}
header_up X-Forwarded-Proto {http.request.scheme}
}
:443, you.domain.net {
tls [email protected]
# 分组,文档: https://caddyserver.com/docs/caddyfile/directives/route
route {
# 文档: https://github.com/klzgrad/naiveproxy/blob/master/README.md
forward_proxy {
basic_auth username somePASSWD
hide_ip
hide_via
probe_resistance
}
# us2.japari-park.net/file
file_server /file {
root /var/www/html
#文件服务器
file_server
}
#反向代理
reverse_proxy / 127.0.0.1:12345 {
import theheaders
}
# webdav相关
# # webdav {
# # root /mnt/somepath/
# # }
# # # 密码验证,不能使用明文,可用指令(caddy hash-password --plaintext 1323321test)生成
# # basicauth {
# # bai JDJhJDE0JHliSVN2Q3lPRXRUSlVQazk1azVCaS5VYnV5Ui9WSmtDaGJ1UkY5TzNxV0dpS1djV2I1V2pX
# # }
} #route
}
运行:
##测试
caddy run -config Caddyfile.conf
##测试通过后,让Caddy在后台运行
caddy start -config Caddyfile.conf
参考链接
https://github.com/mholt/caddy-webdav
https://github.com/klzgrad/naiveproxy
https://github.com/caddyserver/xcaddy
文章评论