服务端
采用 docker compose 管理:docker-compose.yml 文件如下
services:
caddy:
image: caddy:latest
container_name: caddy
ports:
- "80:80"
- "443:443"
volumes:
- ./Caddyfile:/etc/caddy/Caddyfile:ro
- ./caddy_data:/data
- ./caddy_config:/config
- ./web:/web
logging:
driver: "json-file"
options:
max-size: 5m
max-file: 3
xray:
image: teddysun/xray
restart: always
container_name: xray
volumes:
- ./config.json:/etc/xray/config.json
logging:
driver: "json-file"
options:
max-size: 5m
max-file: 3
开启了2个服务,一个是 caddy 用于做网关,xray 做实际代理。采用 caddy 可以方便的自动生成 https 证书。暴露 80 和 443 端口即可。
Caddyfile 文件内容如下:
proxy.123456.xyz {
reverse_proxy /ws xray:10001 {
header_up Host {host}
header_up X-Real-IP {remote}
header_up X-Forwarded-For {remote}
header_up X-Forwarded-Proto {scheme}
}
root * /web
file_server
handle_errors 404 410 {
respond "It's a 404 or 410 error!"
}
handle_errors 5xx {
respond "It's a 5xx error."
}
handle_errors {
respond "It's another error"
}
}
需要提前去设置域名 proxy.123456.xyz 指向 VPS 的 IP 。上面配置的意思是把 https://proxy.123456.xyz/ws 转发到 xray 服务的 10001 端口。web 目录下可以放一个 index.html 文件,内容随意就行。caddy_data 和 caddy_config 目录是存放生成的 caddy 文件的,不用去动里面的内容。
config.json 文件内容:
{
"log": {
"loglevel": "warning"
},
"routing": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"type": "field",
"ip": ["geoip:cn"],
"outboundTag": "block"
},
{
"type": "field",
"protocol": ["bittorrent"],
"outboundTag": "block"
}
]
},
"inbounds": [
{
"port": 10001,
"listen": "0.0.0.0",
"protocol": "vless",
"settings": {
"clients": [
{
"id": "78fa4ba6-7144-474d-a31e-9c79f72abffd"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/ws"
}
},
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls"
]
}
}
],
"outbounds": [
{
"protocol": "freedom"
},
{
"protocol": "blackhole",
"tag": "block"
}
],
"policy": {
"levels": {
"0": {
"handshake": 3,
"connIdle": 256
}
}
}
}
上面的 id 需要修改为自己的,可以去 https://www.uuidgenerator.net/ 网站随机生成一个。主要就是 inbounds 里配置的 10001 端口,使用 vless 协议,网络使用 ws 。这样就基本配好服务端了,目录结构如下:
.
├── Caddyfile
├── caddy_config/
├── caddy_data/
├── config.json
├── docker-compose.yml
└── web/
然后使用命令启动:
docker compose up -d
客户端
以 V2rayNG 为例,点击加号,选择:手动输入VLESS
- 服务器地址: proxy.123456.xyz
- 服务器端口: 443
- 用户ID:78fa4ba6-7144-474d-a31e-9c79f72abffd
- 加密方式:none
- 传输协议:ws
- ws path: /ws
- 传输层安全:tls
- SNI:proxy123456.xyz
- Fingerprint:chrome
- 跳过证书验证:false