Article
C X

Camille X

Building a Tokyo VPS Proxy with Xray REALITY, Hysteria2, and Mihomo

使用 AWS Lightsail、Xray REALITY、Hysteria2 与 Mihomo 搭建可复现的个人双线路网络。

Building a Tokyo VPS Proxy with Xray REALITY, Hysteria2, and Mihomo

本文记录一套已经实测通过的个人网络方案:东京 VPS 同时运行 Xray/REALITY(TCP)和 Hysteria2(UDP),Mac/Linux 使用 Mihomo, Hysteria2 为主线路,REALITY 为 UDP 不可用时的备用线路。

请遵守所在地法律和云服务商条款。不要把真实 UUID、密码、私钥、 REALITY 公钥、短 ID 或完整客户端配置提交到 Git 仓库。

最终拓扑

组件 配置
VPS AWS Lightsail 东京,Ubuntu 24.04 x86_64
套餐 1 GB RAM、2 vCPU、40 GB SSD,约 7 美元/月
主线路 Hysteria2,UDP 443
备用线路 VLESS + XTLS Vision + REALITY,TCP 443
客户端 Clash Verge Rev / Mihomo
策略 fallback:Hysteria2 优先,REALITY 备用

本文用以下占位符表示敏感值:

			<VPS_IP> <UUID> <REALITY_PRIVATE_KEY> <REALITY_PUBLIC_KEY>
<SHORT_ID> <HY2_PASSWORD> <HY2_CERT_SHA256>
	
code
			<VPS_IP> <UUID> <REALITY_PRIVATE_KEY> <REALITY_PUBLIC_KEY>
<SHORT_ID> <HY2_PASSWORD> <HY2_CERT_SHA256>
	
code

1. 创建 Lightsail

  1. 区域选择东京 ap-northeast-1
  2. 系统选择 Ubuntu 24.04、x86_64。
  3. 选择约 7 美元/月的实例规格。
  4. 上传本机 SSH 公钥,创建实例后绑定静态 IPv4。
  5. 云防火墙仅保留:
协议 端口 用途
TCP 22 SSH
TCP 443 REALITY
UDP 443 Hysteria2

若创建向导自动开放 TCP 80,应删除该规则。移动网络公网地址不固定时, SSH 可暂时允许任意来源;有固定办公出口时应限制到该地址。

连接前先确认目标,任何 Agent 都必须先执行:

			ssh ubuntu@<VPS_IP> 'hostname; whoami; pwd; uname -m; lsb_release -ds'
	
code
			ssh ubuntu@<VPS_IP> 'hostname; whoami; pwd; uname -m; lsb_release -ds'
	
code

预期用户为 ubuntu,架构为 x86_64,系统为 Ubuntu 24.04。

2. 安装服务端程序

使用官方安装器:

			sudo apt-get update
sudo apt-get install -y ca-certificates curl jq openssl unzip ufw unattended-upgrades

curl -fsSL --proto '=https' --tlsv1.2 \
  https://github.com/XTLS/Xray-install/raw/main/install-release.sh \
  -o /tmp/xray-install-release.sh
sudo bash /tmp/xray-install-release.sh install

curl -fsSL --proto '=https' --tlsv1.2 \
  https://get.hy2.sh/ -o /tmp/hysteria-install.sh
sudo bash /tmp/hysteria-install.sh
	
code
			sudo apt-get update
sudo apt-get install -y ca-certificates curl jq openssl unzip ufw unattended-upgrades

curl -fsSL --proto '=https' --tlsv1.2 \
  https://github.com/XTLS/Xray-install/raw/main/install-release.sh \
  -o /tmp/xray-install-release.sh
sudo bash /tmp/xray-install-release.sh install

curl -fsSL --proto '=https' --tlsv1.2 \
  https://get.hy2.sh/ -o /tmp/hysteria-install.sh
sudo bash /tmp/hysteria-install.sh
	
code

本次验证版本为 Xray 26.3.27、Hysteria 2.10.0。长期复现时应记录 实际安装版本;升级后重新进行双线路测试。

生成凭据,但不要在终端或日志中打印:

			XRAY_UUID="$(xray uuid)"
XRAY_KEYS="$(xray x25519)"
SHORT_ID="$(openssl rand -hex 8)"
HY2_PASSWORD="$(openssl rand -hex 24)"
	
code
			XRAY_UUID="$(xray uuid)"
XRAY_KEYS="$(xray x25519)"
SHORT_ID="$(openssl rand -hex 8)"
HY2_PASSWORD="$(openssl rand -hex 24)"
	
code

新版 Xray 的公钥字段名是 Password (PublicKey),不能只匹配旧版的 PublicKey。REALITY 公钥虽然由私钥派生,但仍应按客户端凭据管理。

3. 配置 Xray REALITY

写入 /usr/local/etc/xray/config.json

			{
  "log": { "loglevel": "warning" },
  "inbounds": [
    {
      "listen": "0.0.0.0",
      "port": 443,
      "protocol": "vless",
      "settings": {
        "clients": [
          { "id": "<UUID>", "flow": "xtls-rprx-vision" }
        ],
        "decryption": "none"
      },
      "streamSettings": {
        "network": "raw",
        "security": "reality",
        "realitySettings": {
          "show": false,
          "target": "www.apple.com:443",
          "xver": 0,
          "serverNames": ["www.apple.com"],
          "privateKey": "<REALITY_PRIVATE_KEY>",
          "shortIds": ["<SHORT_ID>"]
        }
      }
    }
  ],
  "outbounds": [
    { "protocol": "freedom", "tag": "direct" },
    { "protocol": "blackhole", "tag": "blocked" }
  ]
}
	
code
			{
  "log": { "loglevel": "warning" },
  "inbounds": [
    {
      "listen": "0.0.0.0",
      "port": 443,
      "protocol": "vless",
      "settings": {
        "clients": [
          { "id": "<UUID>", "flow": "xtls-rprx-vision" }
        ],
        "decryption": "none"
      },
      "streamSettings": {
        "network": "raw",
        "security": "reality",
        "realitySettings": {
          "show": false,
          "target": "www.apple.com:443",
          "xver": 0,
          "serverNames": ["www.apple.com"],
          "privateKey": "<REALITY_PRIVATE_KEY>",
          "shortIds": ["<SHORT_ID>"]
        }
      }
    }
  ],
  "outbounds": [
    { "protocol": "freedom", "tag": "direct" },
    { "protocol": "blackhole", "tag": "blocked" }
  ]
}
	
code

本次最初使用 www.microsoft.com 时,Mihomo 与当前 Xray 组合在证书阶段 无法完成握手;改为 www.apple.com 后恢复正常。伪装目标变更后必须同步 修改客户端 servername

			sudo chown root:nogroup /usr/local/etc/xray/config.json
sudo chmod 0640 /usr/local/etc/xray/config.json
sudo xray run -test -config /usr/local/etc/xray/config.json
	
code
			sudo chown root:nogroup /usr/local/etc/xray/config.json
sudo chmod 0640 /usr/local/etc/xray/config.json
sudo xray run -test -config /usr/local/etc/xray/config.json
	
code

4. 配置 Hysteria2

生成自签名证书。客户端同时校验证书 SHA-256 指纹,因此不要只依赖 skip-cert-verify

			sudo install -d -m 0755 /etc/hysteria
sudo openssl req -x509 -nodes -newkey ec \
  -pkeyopt ec_paramgen_curve:prime256v1 \
  -keyout /etc/hysteria/server.key \
  -out /etc/hysteria/server.crt \
  -days 3650 \
  -subj '/CN=www.microsoft.com' \
  -addext 'subjectAltName=DNS:www.microsoft.com'
	
code
			sudo install -d -m 0755 /etc/hysteria
sudo openssl req -x509 -nodes -newkey ec \
  -pkeyopt ec_paramgen_curve:prime256v1 \
  -keyout /etc/hysteria/server.key \
  -out /etc/hysteria/server.crt \
  -days 3650 \
  -subj '/CN=www.microsoft.com' \
  -addext 'subjectAltName=DNS:www.microsoft.com'
	
code

写入 /etc/hysteria/config.yaml

			listen: :443
 
tls:
  cert: /etc/hysteria/server.crt
  key: /etc/hysteria/server.key
  sniGuard: disable
 
auth:
  type: password
  password: "<HY2_PASSWORD>"
 
masquerade:
  type: proxy
  proxy:
    url: https://www.microsoft.com/
    rewriteHost: true
	
code
			listen: :443
 
tls:
  cert: /etc/hysteria/server.crt
  key: /etc/hysteria/server.key
  sniGuard: disable
 
auth:
  type: password
  password: "<HY2_PASSWORD>"
 
masquerade:
  type: proxy
  proxy:
    url: https://www.microsoft.com/
    rewriteHost: true
	
code
			sudo chown -R hysteria:hysteria /etc/hysteria
sudo chmod 0600 /etc/hysteria/config.yaml /etc/hysteria/server.key
sudo chmod 0644 /etc/hysteria/server.crt

openssl x509 -noout -fingerprint -sha256 \
  -in /etc/hysteria/server.crt
	
code
			sudo chown -R hysteria:hysteria /etc/hysteria
sudo chmod 0600 /etc/hysteria/config.yaml /etc/hysteria/server.key
sudo chmod 0644 /etc/hysteria/server.crt

openssl x509 -noout -fingerprint -sha256 \
  -in /etc/hysteria/server.crt
	
code

记录输出的指纹为 HY2_CERT_SHA256,不要记录私钥内容。

5. 防火墙、BBR 与服务

			sudo tee /etc/sysctl.d/99-tokyo-proxy.conf >/dev/null <<'EOF'
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
EOF
sudo sysctl --system

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 443/tcp
sudo ufw allow 443/udp
sudo ufw --force enable

sudo systemctl enable --now xray hysteria-server.service unattended-upgrades
sudo systemctl restart xray hysteria-server.service
	
code
			sudo tee /etc/sysctl.d/99-tokyo-proxy.conf >/dev/null <<'EOF'
net.core.default_qdisc=fq
net.ipv4.tcp_congestion_control=bbr
EOF
sudo sysctl --system

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 443/tcp
sudo ufw allow 443/udp
sudo ufw --force enable

sudo systemctl enable --now xray hysteria-server.service unattended-upgrades
sudo systemctl restart xray hysteria-server.service
	
code

验收:

			sudo systemctl is-active xray hysteria-server.service
sudo ss -lntup | grep ':443'
sudo ufw status
sysctl net.ipv4.tcp_congestion_control
	
code
			sudo systemctl is-active xray hysteria-server.service
sudo ss -lntup | grep ':443'
sudo ufw status
sysctl net.ipv4.tcp_congestion_control
	
code

预期 TCP 443 由 Xray 监听,UDP 443 由 Hysteria 监听,拥塞控制为 BBR。

6. Mihomo 客户端配置

将下列配置保存为只读私密文件,例如 tokyo-proxy-mihomo.yaml

			mixed-port: 7890
allow-lan: false
bind-address: 127.0.0.1
mode: rule
log-level: info
ipv6: false
unified-delay: true
tcp-concurrent: true
 
profile:
  store-selected: true
  store-fake-ip: true
 
dns:
  enable: true
  listen: 127.0.0.1:1053
  ipv6: false
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  nameserver:
    - https://1.1.1.1/dns-query
    - https://8.8.8.8/dns-query
  proxy-server-nameserver:
    - https://223.5.5.5/dns-query
    - https://1.12.12.12/dns-query
 
tun:
  enable: true
  stack: mixed
  auto-route: true
  auto-detect-interface: true
  dns-hijack:
    - any:53
 
proxies:
  - name: TOKYO-REALITY
    type: vless
    server: <VPS_IP>
    port: 443
    uuid: <UUID>
    flow: xtls-rprx-vision
    packet-encoding: xudp
    udp: true
    tls: true
    servername: www.apple.com
    client-fingerprint: chrome
    reality-opts:
      public-key: <REALITY_PUBLIC_KEY>
      short-id: <SHORT_ID>
    encryption: ""
    network: tcp
 
  - name: TOKYO-HY2
    type: hysteria2
    server: <VPS_IP>
    port: 443
    password: <HY2_PASSWORD>
    sni: www.microsoft.com
    skip-cert-verify: true
    fingerprint: "<HY2_CERT_SHA256>"
    alpn:
      - h3
 
proxy-groups:
  - name: PROXY
    type: fallback
    proxies:
      - TOKYO-HY2
      - TOKYO-REALITY
    url: https://www.gstatic.com/generate_204
    interval: 300
 
rules:
  - IP-CIDR,<VPS_IP>/32,DIRECT,no-resolve
  - IP-CIDR,127.0.0.0/8,DIRECT,no-resolve
  - IP-CIDR,10.0.0.0/8,DIRECT,no-resolve
  - IP-CIDR,172.16.0.0/12,DIRECT,no-resolve
  - IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
  - IP-CIDR,169.254.0.0/16,DIRECT,no-resolve
  - MATCH,PROXY
	
code
			mixed-port: 7890
allow-lan: false
bind-address: 127.0.0.1
mode: rule
log-level: info
ipv6: false
unified-delay: true
tcp-concurrent: true
 
profile:
  store-selected: true
  store-fake-ip: true
 
dns:
  enable: true
  listen: 127.0.0.1:1053
  ipv6: false
  enhanced-mode: fake-ip
  fake-ip-range: 198.18.0.1/16
  nameserver:
    - https://1.1.1.1/dns-query
    - https://8.8.8.8/dns-query
  proxy-server-nameserver:
    - https://223.5.5.5/dns-query
    - https://1.12.12.12/dns-query
 
tun:
  enable: true
  stack: mixed
  auto-route: true
  auto-detect-interface: true
  dns-hijack:
    - any:53
 
proxies:
  - name: TOKYO-REALITY
    type: vless
    server: <VPS_IP>
    port: 443
    uuid: <UUID>
    flow: xtls-rprx-vision
    packet-encoding: xudp
    udp: true
    tls: true
    servername: www.apple.com
    client-fingerprint: chrome
    reality-opts:
      public-key: <REALITY_PUBLIC_KEY>
      short-id: <SHORT_ID>
    encryption: ""
    network: tcp
 
  - name: TOKYO-HY2
    type: hysteria2
    server: <VPS_IP>
    port: 443
    password: <HY2_PASSWORD>
    sni: www.microsoft.com
    skip-cert-verify: true
    fingerprint: "<HY2_CERT_SHA256>"
    alpn:
      - h3
 
proxy-groups:
  - name: PROXY
    type: fallback
    proxies:
      - TOKYO-HY2
      - TOKYO-REALITY
    url: https://www.gstatic.com/generate_204
    interval: 300
 
rules:
  - IP-CIDR,<VPS_IP>/32,DIRECT,no-resolve
  - IP-CIDR,127.0.0.0/8,DIRECT,no-resolve
  - IP-CIDR,10.0.0.0/8,DIRECT,no-resolve
  - IP-CIDR,172.16.0.0/12,DIRECT,no-resolve
  - IP-CIDR,192.168.0.0/16,DIRECT,no-resolve
  - IP-CIDR,169.254.0.0/16,DIRECT,no-resolve
  - MATCH,PROXY
	
code

VPS_IP/32,DIRECT 非常重要,可避免 Mihomo 的服务器连接再次进入代理, 形成回环。

7. Mac 部署

  1. Clash Verge Rev 官方发布页 下载与 CPU 架构匹配的安装包。
  2. 使用 hdiutil verifycodesign --verify --deep --strictspctl -a -vv 校验安装包及应用签名。
  3. 在 Profiles 中导入 tokyo-proxy-mihomo.yaml 并激活。
  4. 优先启用 TUN;若没有管理员权限,先启用 System Proxy。
  5. 开启静默启动和登录自启动。

本次两台 Mac 的结果:

  • MacBook Pro:Clash Verge Rev 2.5.1,TUN 已启用。
  • MacBook Air:Clash Verge Rev 2.5.1,System Proxy 已启用,登录时静默启动; TUN 仍需在 Air 本机完成一次管理员授权。

自动化 Agent 更新现有 Clash Verge 配置时,应先退出应用、备份 profiles.yaml,再写入新 Profile;不得覆盖或删除原有机场订阅。

8. iOS 客户端

推荐使用 Stash , 它支持 Clash 配置、Hysteria2、VLESS-TCP-REALITY 和 XTLS Vision。

不要直接照搬 Mihomo 配置中的 Hysteria2 节点,Stash 使用不同字段:

			- name: TOKYO-HY2
  type: hysteria2
  server: <VPS_IP>
  port: 443
  auth: <HY2_PASSWORD>
  sni: www.microsoft.com
  server-cert-fingerprint: <HY2_CERT_SHA256_WITHOUT_COLONS>
  alpn:
    - h3
	
code
			- name: TOKYO-HY2
  type: hysteria2
  server: <VPS_IP>
  port: 443
  auth: <HY2_PASSWORD>
  sni: www.microsoft.com
  server-cert-fingerprint: <HY2_CERT_SHA256_WITHOUT_COLONS>
  alpn:
    - h3
	
code

REALITY 节点的 flowclient-fingerprintservernamereality-opts 与桌面配置保持一致。删除桌面专用的 mixed-porttunbind-address 等字段。

导入方式:

  1. 将 Stash YAML 通过 AirDrop 发送到 iPhone,或保存到"文件"App。
  2. 分享/打开该文件时选择 Stash。
  3. 在 Stash 的"配置文件"中选中它,回到首页点击"启动"。
  4. 分别测试 Hysteria2 与 REALITY,再确认出口 IP 和地区。

本地文件导入不会把凭据上传到第三方订阅服务。参考 Stash 官方快速开始

如果使用 Shadowrocket,不要导入上述 Stash YAML;应分别生成并扫码导入 两个标准节点 URI:

			vless://UUID@VPS_IP:443?...REALITY参数...#TOKYO-REALITY
hysteria2://AUTH@VPS_IP:443/?sni=...&insecure=1&pinSHA256=...#TOKYO-HY2
	
code
			vless://UUID@VPS_IP:443?...REALITY参数...#TOKYO-REALITY
hysteria2://AUTH@VPS_IP:443/?sni=...&insecure=1&pinSHA256=...#TOKYO-HY2
	
code

Shadowrocket 中可手动选择节点,但不会自动继承 Mihomo/Stash YAML 内的 fallback 策略。二维码包含完整认证信息,必须按密码文件保护。

9. Linux 客户端

无桌面 Linux 可直接运行 Mihomo:

			sudo install -d -m 0750 /etc/mihomo
sudo install -m 0600 tokyo-proxy-mihomo.yaml /etc/mihomo/config.yaml
sudo mihomo -t -f /etc/mihomo/config.yaml
	
code
			sudo install -d -m 0750 /etc/mihomo
sudo install -m 0600 tokyo-proxy-mihomo.yaml /etc/mihomo/config.yaml
sudo mihomo -t -f /etc/mihomo/config.yaml
	
code

TUN 模式需要 root 或 CAP_NET_ADMIN。若只需要给单个程序使用,可关闭 tun.enable,再设置:

			export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
export ALL_PROXY=socks5://127.0.0.1:7890
	
code
			export HTTP_PROXY=http://127.0.0.1:7890
export HTTPS_PROXY=http://127.0.0.1:7890
export ALL_PROXY=socks5://127.0.0.1:7890
	
code

10. 端到端验证

先验证配置语法:

			mihomo -t -f tokyo-proxy-mihomo.yaml
	
code
			mihomo -t -f tokyo-proxy-mihomo.yaml
	
code

分别对两个节点进行延迟测试,然后检查出口:

			curl --proxy http://127.0.0.1:7890 https://api.ipify.org
curl --proxy http://127.0.0.1:7890 \
  https://www.gstatic.com/generate_204 -o /dev/null -w '%{http_code}\n'
curl --proxy http://127.0.0.1:7890 \
  https://1.1.1.1/cdn-cgi/trace | grep -E '^(loc|http|warp)='
	
code
			curl --proxy http://127.0.0.1:7890 https://api.ipify.org
curl --proxy http://127.0.0.1:7890 \
  https://www.gstatic.com/generate_204 -o /dev/null -w '%{http_code}\n'
curl --proxy http://127.0.0.1:7890 \
  https://1.1.1.1/cdn-cgi/trace | grep -E '^(loc|http|warp)='
	
code

预期:出口为 VPS 静态 IP、HTTPS 状态码为 204、地区为 JP。 本次北京移动网络实测延迟约 60–80 ms。

11. 常见故障

现象 处理
REALITY 返回 EOF 核对公钥、短 ID、SNI;尝试证书链更小的伪装站点
服务端显示 invalid connection 临时开启 show: true 和 debug 日志,修复后立即关闭
Hysteria2 不通 检查 Lightsail 与 UFW 是否同时放行 UDP 443
只有一个节点可用 确认 TCP/UDP 分别由 Xray/Hysteria 监听
客户端连接来源变成 VPS 自身 IP 增加 VPS_IP/32,DIRECT,消除代理回环
Clash Verge 启动两个内核 退出 GUI,终止残留 verge-mihomo 后单实例重启
Mac 无法启用 TUN 在本机安装辅助服务并完成一次管理员授权,期间可用 System Proxy

Agent 交付清单

  • 写操作前确认 hostnamewhoamipwd
  • 不在回复、日志或 Git 中输出任何真实凭据。
  • 固定 IP 后再生成客户端配置。
  • 云防火墙与 UFW 同时限制为 22/TCP、443/TCP、443/UDP。
  • Xray/Hysteria 配置文件权限为 0640 或更严格,客户端配置为 0600
  • 两个服务均为 activeenabled,BBR 已启用。
  • Hysteria2、REALITY 必须分别完成真实 HTTPS 测试。
  • 验证 TUN 或 System Proxy 的实际出口,而不只是检查进程状态。
  • 保留原客户端订阅及配置备份,确保可以回退。

参考文档:

Camille-X | © 2026

Made with

svelte-logo
C. Camille / Blog