Skip to content

Instantly share code, notes, and snippets.

@shuanghua
Last active October 20, 2020 22:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shuanghua/22c7f5fb558fdac27411b6c83614c04b to your computer and use it in GitHub Desktop.
Save shuanghua/22c7f5fb558fdac27411b6c83614c04b to your computer and use it in GitHub Desktop.

下载 caddy2

去 caddy2 官方 github 下载和 Linux 系统对应的可执行文件 https://github.com/caddyserver/caddy/releases 尽可能下载最新的版本,因为 bug 少,下载完成后并移动到 /usr/bin/ 下 (如果你有能力也可以下载源码进行编译安装)

Caddyfile 有两种配置写法

  • 第一种:
{
	experimental_http3
}
yourdomain.com {
	root * /var/www/html
	file_server
	encode zstd gzip
	tls /root/.acme.sh/yourdomain.com/fullchain.cer /root/.acme.sh/yourdomain.com/yourdomain.com.key

	reverse_proxy /ss localhost:10808
}

第一种方式还需要在 v2ray-plugin 的 plugin_opts 中填写 path=/ss

  • 第二种方式
{
	experimental_http3
}
yourdomain.com {
	root * /var/www/html
	file_server
	encode zstd gzip
	tls /root/.acme.sh/yourdomain.com/fullchain.cer /root/.acme.sh/yourdomain.com/yourdomain.com.key

	route /ss* {
		uri strip_prefix /ss
		reverse_proxy localhost:10808
	}
}

第二种方式不需要在 v2ray-plugin 的 plugin_opts 中填写 path=/ss

我原来用的就是ss + v2ray-plugin 的形式,所以这里 caddy tls 我直接使用原来 acme 脚本申请的 cf 证书;并且对网站设置支持 http3 访问.

ss 服务器端配置, 去掉 tls, tls 交给了 caddy 去完成 (这里使用了上面第一种 Caddy 配置)

{
  "server": "0.0.0.0",
  "nameserver": "1.1.1.1",
  "server_port": 10808,
  "password": "password",
  "method": "chacha20-ietf-poly1305",
  "timeout": 400,
  "no_delay": true,
  "reuse_port": true,
  "workers": 1, 
  "mode": "tcp_and_udp",
  "plugin": "/usr/bin/v2ray-plugin",
  "plugin_opts": "server;host=yourdomian.xom;loglevel=none;path=/ss"
}

ss 客户端

tls;host=yourdomain.com;path=/ss

运行 caddy

caddy start --config /root/Caddyfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment