本指南基于阿里云香港ECS(Ubuntu 20.04/22.04)搭建 v2ray(推荐 xray/v2ray-core 的 VLESS+WS+TLS),在应用层用 TLS + websocket 隐蔽流量,在传输层通过系统优化(BBR、TCP Fast Open、Nginx keepalive)提升延迟与带宽表现。准备一域名并能解析到VPS公网IP,控制台打开相应端口(80/443)与安全组。
步骤:1)选择香港地域的ECS,最低配置按需求(1vCPU+1GB起用于轻量用途)。2)镜像推荐 Ubuntu 20.04/22.04。3)创建时记下公网IP、登录密钥或密码。4)在「安全组」规则允许入站 TCP 80、443,出站全部允许。5)在域名服务处添加 A 记录指向公网IP,等待解析生效(可用 ping 或 dig 验证)。
SSH 登录:ssh root@your_ip(若用密钥则 ssh -i key.pem root@ip)。登录后更新系统并安装必要包:apt update && apt upgrade -y;apt install -y curl wget git net-tools unzip socat nginx certbot python3-certbot-nginx
推荐用 Certbot 与 Nginx 自动获取证书。先创建一个临时 Nginx 配置以响应 80。示例:在 /etc/nginx/sites-available/default 中配置 server_name your.domain; listen 80; location /.well-known/acme-challenge/ { root /var/www/html; } 然后 systemctl restart nginx。运行:certbot --nginx -d your.domain --non-interactive --agree-tos -m your@mail.com。证书路径通常 /etc/letsencrypt/live/your.domain/。
官方安装脚本可以快速部署(示例以 v2ray 官方脚本为例):bash <(curl -L -s https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)。安装好后,服务文件位于 /usr/bin/v2ray 与 /etc/systemd/system/v2ray.service。若偏好 xray,替换为 xray-core 的脚本或手动部署。
生成 UUID:apt install -y uuid-runtime;uuid=$(uuidgen)。编辑 /etc/v2ray/config.json(示例核心字段):{"inbounds":[{"port":10000,"listen":"127.0.0.1","protocol":"vless","settings":{"clients":[{"id":"YOUR-UUID","flow":"","level":0}]},"streamSettings":{"network":"ws","wsSettings":{"path":"/ray","headers":{"Host":"your.domain"}}}}],"outbounds":[{"protocol":"freedom","settings":{}}]}. 将 YOUR-UUID 替换为 uuid。
在 /etc/nginx/sites-available/your.domain.conf 写入:server { listen 443 ssl http2; server_name your.domain; ssl_certificate /etc/letsencrypt/live/your.domain/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/your.domain/privkey.pem; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers '...'; location /ray { proxy_redirect off; proxy_pass http://127.0.0.1:10000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; } } 然后 nginx -t && systemctl reload nginx。
本地UFW(如使用):ufw allow 80/tcp; ufw allow 443/tcp; ufw enable。阿里云控制台安全组需放行 80/443(以及你用于内部 v2ray 的端口若有需要)。确保没有其他中间件占用 443。
systemctl enable v2ray && systemctl start v2ray。查看日志:journalctl -u v2ray -f。在客户端用 VLESS+WS+TLS 配置(填写域名、路径 /ray、uuid、TLS开启)。若能连通并能浏览网页即部署成功。
开启 BBR:在 /etc/sysctl.conf 添加 net.core.default_qdisc = fq; net.ipv4.tcp_congestion_control = bbr;执行 sysctl -p。启用 TCP Fast Open:echo 3 > /proc/sys/net/ipv4/tcp_fastopen;为了开机生效在 sysctl.conf 或 rc.local 写入。确认 bbr:sysctl net.ipv4.tcp_congestion_control; lsmod | grep bbr。
在 nginx.conf 中调整 worker_processes auto; worker_connections 10240; keepalive_timeout 65; server_tokens off; 在 ssl 配置中启用 TLS1.3,调优曲线并启用 session cache、OCSP Stapling(ssl_stapling on; ssl_stapling_verify on; resolver 8.8.8.8;)。这些能减少握手延迟并提升并发吞吐。
1)不要在配置文件中暴露敏感注释;2)使用随机路径(/ray-随机字符串)并在 Nginx 做伪装站点;3)定期更换 UUID;4)限制 v2ray 监听为 127.0.0.1 并由 Nginx 反代;5)开启 fail2ban 针对 SSH、防止暴力攻击。
建议安装简单监控:vnstat、iftop、nload 或使用 Prometheus+Grafana(复杂场景)。观察延迟、丢包与并发连接,按需增加带宽或升级实例。若遇不可控波动,考虑多点冗余或 CDN 前置。
定期备份 /etc/v2ray 、/etc/nginx 以及证书目录。可写简单脚本每周 scp 到另一台托管。证书自动续期:certbot renew --dry-run,确保 renew 后 nginx reload。
答:境外(香港)服务器通常不受大陆ICP备案要求约束,但若你通过域名指向大陆用户访问或使用大陆 CDN,可能涉及备案问题。使用香港 VPS 对于绕过大陆监管有帮助,但请遵守当地与服务提供方政策,避免触犯法规。
答:VLESS 是更轻量、无加密负载头的协议(需 TLS 提供加密),与 WebSocket 混合可更好伪装为普通 HTTPS 流量。性能上因为没有额外协议层开销(相比旧版本的混淆),延迟与吞吐表现通常更好;结合 Nginx TLS 优化、BBR 可进一步降低延迟与提高带宽。
答:先从最外层到内层排查:1)域名解析是否正确(ping/host);2)安全组与防火墙是否放通 443/80;3)nginx 是否正常并能访问 /.well-known;4)证书是否有效(openssl s_client -connect your.domain:443);5)v2ray 日志(journalctl -u v2ray)看是否报错;6)网络丢包/带宽限制(mtr、iperf),最后检查客户端配置(路径、UUID、TLS开启)。
