xray+sing-box用法
服务端运行xray,通过容器方式运行,客户端运行sing-box,本例子通过本地方式运行
涉及镜像:
ghcr.io/xtls/xray-core:latest
服务端
1、创建目录
mkdir /data/xray
2、生成UUID和Reality密钥
docker run --rm --entrypoint xray ghcr.io/xtls/xray-core uuid #uuid
执行后可以看到有个UUID输出在终端上,最下方,比如:
71dbc39e-***********
再次执行命令生成Reality密钥
docker run --rm --entrypoint xray ghcr.io/xtls/xray-core x25519
可以看到类似如下输出:
PrivateKey: 4Oe8****
Password (PublicKey): 0fyZN3B8L***
Hash32: NWx1aC0jYsn_pqJ4U***
3、编辑vim /data/xray/config.json,内容如下:
{
"log": {
"loglevel": "info"
},
"inbounds": [
{
"tag": "vless-reality-in",
"listen": "0.0.0.0",
"port": 443,
"protocol": "vless",
"settings": {
"clients": [
{
"id": "UUID",
"email": "user1",
"flow": "xtls-rprx-vision"
}
],
"decryption": "none"
},
"streamSettings": {
"network": "tcp",
"security": "reality",
"realitySettings": {
"show": false,
"dest": "www.cloudflare.com:443",
"xver": 0,
"serverNames": [
"www.cloudflare.com"
],
"privateKey": "私钥",
"shortIds": [
"02625182af"
]
}
},
"sniffing": {
"enabled": true,
"destOverride": [
"http",
"tls",
"quic"
]
}
}
],
"outbounds": [
{
"tag": "direct",
"protocol": "freedom"
},
{
"tag": "block",
"protocol": "blackhole"
}
]
}
4、编辑vim /data/xray/docker-compose.yml,内容如下:
services:
xray:
image: ghcr.io/xtls/xray-core:latest
container_name: xray
restart: unless-stopped
ports:
- "443:443/tcp"
volumes:
- ./config.json:/usr/local/etc/xray/config.json:ro
command: ["run", "-config", "/usr/local/etc/xray/config.json"]
5、启动
docker-compose up -d
客户端
1、安装sing-box(本例子为:1.13.14版本)
curl -fsSL https://sing-box.app/install.sh | sh
2、编辑vim /etc/sing-box/config.json,内容如下:
{
"log": {
"level": "info",
"timestamp": true
},
"dns": {
"servers": [
{
"type": "udp",
"tag": "dns-cn",
"server": "223.5.5.5",
"server_port": 53
},
{
"type": "https",
"tag": "dns-remote",
"server": "1.1.1.1",
"server_port": 443,
"path": "/dns-query",
"tls": {
"enabled": true,
"server_name": "cloudflare-dns.com"
},
"detour": "proxy"
}
],
"rules": [
{
"domain_suffix": [
".cn"
],
"action": "route",
"server": "dns-cn"
}
],
"final": "dns-remote",
"strategy": "prefer_ipv4",
"cache_capacity": 4096
},
"inbounds": [
{
"type": "http",
"tag": "http-in",
"listen": "0.0.0.0",
"listen_port": 17890
}
],
"outbounds": [
{
"type": "vless",
"tag": "proxy",
"server": "服务端地址(ip或者域名)",
"server_port": 443,
"uuid": "UUID与服务端对应",
"flow": "xtls-rprx-vision",
"network": "tcp",
"tls": {
"enabled": true,
"server_name": "www.cloudflare.com",
"utls": {
"enabled": true,
"fingerprint": "chrome"
},
"reality": {
"enabled": true,
"public_key": "服务端生成的公钥",
"short_id": "02625182af"
}
}
}
],
"route": {
"default_domain_resolver": {
"server": "dns-cn",
"strategy": "prefer_ipv4"
},
"rules": [
{
"action": "sniff"
},
{
"protocol": "dns",
"action": "hijack-dns"
},
{
"domain_suffix": [
".cn",
".baidu.com",
".qq.com",
".weixin.qq.com",
"cn.bing.com"
],
"action": "route",
"outbound": "direct"
},
{
"domain_suffix": [
".ad.com",
".ads.com"
],
"action": "route",
"outbound": "block"
}
],
"final": "proxy",
"auto_detect_interface": true
}
}
- short_id:要与服务端对应,可自定义,要16进制开头的,并且只能是偶数个数8位或者10位这样
- flow: 也要与服务端对应
- 17890: 可自定义,主要用作给其他机器代理用
3、检测配置并启动,如下:
sing-box check -c /etc/sing-box/config.json
systemctl restart sing-box

本机测试:

其他windows机器直接在代理位置配置对应的IP和17890端口即可,如果是linux,可通过如下配置
export http_proxy=http://ip:18790
export https_proxy=http://ip:18790


