💬 前言
在看本文之前请先确保你看过上一篇.
本人由于时常往返国内外,因此就对双向的反代都有需求,为了不开很多个服务器,且为了增加灵活性,我就对多向的反代有所需求.
📐 架构设计
先回顾一下之前单向的版本:
在之前的文章中提到过 V2Ray 自带的路由功能,以及 Bridge 和 Portal 之间的关系,所以我们利用域名作为标签,在路由设置中设置分流,对外开放不同的 inbound 来区分需求,就可以实现我们的需求,最终的架构图如下:
每个机器内部的实线部分是我们在配置文件中明文书写的,虚线部分是 V2Ray 自动完成的,这里以 B 服务器在日本, A1服务器在法国, A2 服务器在中国为例.
📃 配置文件
A (其中一台为例):
{
"log": {
"loglevel": "debug"
},
"reverse": {
"bridges": [
{
"tag": "bridge",
"domain": "fr-jp.tunnel"
}
]
},
"outbounds": [
{
"tag": "tunnel",
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "-",
"port": 443,
"users": [
{
"id": "-",
"alterId": 0
}
]
}
]
},
"streamSettings": {
"network": "ws",
"security": "tls",
"wsSettings": {
"path": "/tunnel"
}
}
},
{
"tag": "out",
"protocol": "freedom",
"settings": {}
}
],
"routing": {
"rules": [
{
"type": "field",
"inboundTag": [
"bridge"
],
"domain": [
"full:fr-jp.tunnel"
],
"outboundTag": "tunnel"
},
{
"type": "field",
"inboundTag": [
"bridge"
],
"outboundTag": "out"
}
]
}
}
B (这里面还有个 no-reverse-proxy 的 inbound 用来直接通过这台机器代理,不再反向代理):
{
"log": {
"loglevel": "debug"
},
"reverse": {
"portals": [
{
"tag": "portal-fr",
"domain": "fr-jp.tunnel"
},
{
"tag": "portal-cn",
"domain": "cn-jp.tunnel"
}
]
},
"inbounds": [
{
"tag": "no-reverse-proxy",
"port": 5000,
"listen": "127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "-",
"alterId": 0
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/saratoga"
}
}
},
{
"tag": "tunnel2fr",
"port": 10000,
"listen": "127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "-",
"alterId": 0
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/tunnel2fr"
}
}
},
{
"tag": "tunnel2cn",
"port": 10001,
"listen": "127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "-",
"alterId": 0
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/tunnel2cn"
}
}
},
{
"tag": "tunnel",
"port": 20000,
"listen": "127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "-",
"alterId": 0
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/tunnel"
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
}
],
"routing": {
"rules": [
{
"type": "field",
"inboundTag": [
"tunnel"
],
"domain": [
"full:fr-jp.tunnel"
],
"outboundTag": "portal-fr"
},
{
"type": "field",
"inboundTag": [
"tunnel"
],
"domain": [
"full:cn-jp.tunnel"
],
"outboundTag": "portal-cn"
},
{
"type": "field",
"inboundTag": [
"tunnel2fr"
],
"outboundTag": "portal-fr"
},
{
"type": "field",
"inboundTag": [
"tunnel2cn"
],
"outboundTag": "portal-cn"
}
]
}
}
B 机器上网页服务器中的设置相应地增加一个转发规则就行了.
Comments NOTHING