前言
我常年在国外生活,喜欢在喜马拉雅上听有声书、广播剧放松一下。但有些资源在海外受限,不能直接收听,挺不方便的。 反过来,每次回国探亲时,我日常使用的 Gmail、Google Docs、YouTube、ChatGPT 等服务又经常无法访问,生活和工作都受到影响。
尝试过一些付费 VPN 或加速服务,但要么价格不低,要么稳定性不佳。于是我开始研究一些网络优化方案,自己动手搭建「双向访问」环境,既能在国外用国内的应用,又能在国内访问常用的国际网站。
这篇文章算是我的经验记录,分享一些技术思路和工具,帮助有类似需求的人少走弯路。所有方法仅用于个人学习和网络优化,请勿用于违反平台政策的用途。
Part 1:国外访问国内资源(Shadowsocks + 阿里云 ECS)
步骤 1:购买阿里云 ECS
- 登录 阿里云官网。
- 注册并完成实名认证。
- 选择 “云服务器 ECS” -> “立即购买”。
- 选择 地域:北京、杭州或上海。
- 系统镜像:Ubuntu 22.04 LTS。
- 配置:1核 1GB 内存即可,带宽选 1~3 Mbps。
- 确认订单并购买。
提示: 不需要备案,因为这里只是跑代理服务。
步骤 2:安装 Shadowsocks 服务端
SSH 登录服务器:
ssh root@<你的ECS公网IP>
更新系统并安装 Shadowsocks:
sudo apt update && sudo apt upgrade -y
sudo apt install shadowsocks-libev -y
配置 /etc/shadowsocks-libev/config.json
:
{
"server":"0.0.0.0",
"server_port":8388,
"password":"<your_password>", // 请替换为自己的密码
"timeout":300,
"method":"aes-256-gcm"
}
启动 Shadowsocks:
sudo systemctl enable shadowsocks-libev
sudo systemctl restart shadowsocks-libev
步骤 3:安全组与防火墙
- 阿里云控制台 -> ECS -> 安全组 -> 添加规则:开放 TCP/UDP 8388 端口。
- 服务器:
sudo ufw allow 8388/tcp
sudo ufw allow 8388/udp
sudo ufw enable
步骤 4:客户端配置
iPhone/iPad(Shadowrocket)
-
从 App Store 下载 Shadowrocket(付费应用,价格合理)。
-
添加服务器:
- 类型:Shadowsocks
- 地址:你的 ECS IP
- 端口:8388
- 密码:<your_password>
- 加密:aes-256-gcm
-
导入“回国规则”:
- 电脑打开 回国规则链接
- Shadowrocket -> 配置 -> 点击右上角二维码 -> 扫描电脑上的二维码。
macOS/Windows(Clash Verge)
- 下载 Clash Verge。
- 编辑
config.yaml
文件:
port: 7890
socks-port: 7891
allow-lan: true
mode: rule
log-level: info
proxies:
- name: "CN-SS"
type: ss
server: <你的ECS IP>
port: 8388
cipher: aes-256-gcm
password: <your_password>
proxy-groups:
- name: "Proxy"
type: select
proxies:
- "CN-SS"
- DIRECT
rules:
- DOMAIN-SUFFIX,ximalaya.com,Proxy
- DOMAIN-SUFFIX,bilibili.com,Proxy
- GEOIP,CN,Proxy
- MATCH,DIRECT
- Clash Verge -> 配置文件 -> 导入该 YAML 文件。
Part 2:国内访问国际资源(V2Ray + TLS + WS + AWS EC2)
为什么要配置域名和 SSL 证书?
TLS 可以伪装成普通 HTTPS 流量,避免被拦截。域名与证书让服务更稳定、安全。
步骤 1:AWS EC2
- 注册 AWS。
- 创建 Ubuntu 24.04 LTS 实例,开放 80/443 端口。
步骤 2:域名与 SSL(Certbot)
- 将域名解析到 EC2 IP。
- 安装 Nginx 与 Certbot:
sudo apt install nginx certbot python3-certbot-nginx -y
sudo certbot --nginx -d your_domain.com
步骤 3:安装 V2Ray 并生成 UUID
cat /proc/sys/kernel/random/uuid # 复制UUID
bash <(curl -Ls https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
编辑 /usr/local/etc/v2ray/config.json
并替换 <your-uuid>
。
步骤 4:Nginx 反向代理
配置 /etc/nginx/sites-enabled/default
:
location /ray {
proxy_pass http://127.0.0.1:10000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
步骤 5:客户端配置
Shadowrocket
- 类型:Vmess
- 地址:your_domain.com
- 端口:443
- 用户ID:<your-uuid>
- TLS:开启
- 路径:/ray
Clash Verge 示例:
proxies:
- name: "US-V2Ray"
type: vmess
server: your_domain.com
port: 443
uuid: <your-uuid>
tls: true
network: ws
ws-opts:
path: /ray
总结
通过这套方案,我在国外能用喜马拉雅、Bilibili;回国时 Gmail、Google、YouTube 也能正常访问。如果你有疑问或建议,欢迎在留言区分享你的想法!