1) 前提:已在腾讯云香港购买CVM(Linux,推荐Ubuntu 20.04/22.04)并绑定弹性公网IP(EIP);2) 准备域名并在域名管理处添加A记录指向EIP;3) 在腾讯云控制台安全组/防火墙放行端口:22(SSH)、80(HTTP)、443(HTTPS);4) 本文以root或sudo用户操作。
1) SSH登录:ssh root@你的EIP;2) 更新并安装基础工具:apt update && apt upgrade -y && apt install -y curl wget git unzip socat nginx uuid-runtime;3) 确认域名已解析到该EIP:dig +short your.domain
1) 推荐使用官方安装脚本:bash <(curl -L -s https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh);2) 脚本会安装二进制与 systemd 服务,默认配置文件路径:/usr/local/etc/v2ray/config.json;3) 生成 uuid:uuid=$(cat /proc/sys/kernel/random/uuid) 并记录用于客户端。
1) 编辑 /usr/local/etc/v2ray/config.json,示例 inbound(仅示例须替换UUID与路径):{ "inbounds":[{ "port":10000,"listen":"127.0.0.1","protocol":"vmess","settings":{ "clients":[{"id":"你的-UUID","alterId":0}] },"streamSettings":{"network":"ws","wsSettings":{"path":"/ray"}} }], "outbounds":[{"protocol":"freedom","settings":{}}] };2) 保存并不要启用TLS(TLS由Nginx终端处理)。
1) 在 /etc/nginx/sites-available/ 创建配置文件 your.domain.conf,关键配置示例:server { listen 80; server_name your.domain; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name your.domain; ssl_certificate /etc/letsencrypt/live/your.domain/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/your.domain/privkey.pem; 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 $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } };2) 启用配置:ln -s /etc/nginx/sites-available/your.domain.conf /etc/nginx/sites-enabled/;3) 测试并重启:nginx -t && systemctl restart nginx。
1) 安装 acme.sh:curl https://get.acme.sh | sh && source ~/.bashrc;2) 用 nginx 插件或 webroot 模式申请证书(示例用 nginx):~/.acme.sh/acme.sh --issue --nginx -d your.domain;3) 若成功,安装证书到系统位置并指明重载命令:~/.acme.sh/acme.sh --install-cert -d your.domain --key-file /etc/letsencrypt/live/your.domain/privkey.pem --fullchain-file /etc/letsencrypt/live/your.domain/fullchain.pem --reloadcmd "systemctl reload nginx"。
1) acme.sh 默认会安装 cron 定期续签,你也可以手动添加:~/.acme.sh/acme.sh --upgrade --auto-upgrade;2) 若需要在续签后额外重启 v2ray,请加入 --reloadcmd "systemctl restart nginx v2ray";3) 检查 cron:crontab -l 或 /etc/cron.d/acme.sh,确保续签脚本存在。
1) 启用并启动服务:systemctl enable --now nginx v2ray;2) 查看状态与日志:systemctl status v2ray nginx;journalctl -u v2ray -f 与 journalctl -u nginx -f;3) 本地测试:curl -I https://your.domain 返回 200 并且证书信息有效。
1) 证书申请失败:检查域名解析、80端口是否被占用以及安全组是否放行;2) WebSocket 连接失败:确认 Nginx 转发配置中的 Upgrade/Connection 设置正确,v2ray 的 ws path 与客户端一致;3) 权限问题:证书文件权限应能被 nginx 读取(通常放在 /etc/letsencrypt/live/)。
1) 建议只对 80/443 公开,v2ray 内部监听设为 127.0.0.1 并通过 Nginx 代理;2) 定期更新系统与 v2ray,定期检查续签日志;3) 使用复杂 UUID 与合适路径,并在客户端配置相同路径与UUID。
问:证书会自动续签吗?如何确认续签成功? 答:如果用 acme.sh 安装,默认会添加 cron 定期检查并续签(默认每天检查)。可用~/.acme.sh/acme.sh --cron运行一次手动检测,或查看 crontab。续签后 acme.sh 的 --reloadcmd 会执行重载命令,查看 /root/.acme.sh/your.domain/ 下的日志与 /var/log/cron(或 journalctl)确认。
问:域名刚修改DNS,解析未生效能申请到证书吗? 答:不能。Let's Encrypt 需要域名解析生效并指向服务器的公网IP(用于HTTP或DNS验证)。使用 dig +short your.domain 或 nslookup 检查解析是否正确,生效后再申请证书。
问:能不通过 Nginx,直接让 v2ray 自己做 TLS 吗? 答:可以,v2ray 支持直接开启TLS(streamSettings.tlsSettings),但运维上常用 Nginx 做证书管理与反向代理,便于扩展与复用。如果直接在 v2ray 配置 TLS,证书申请与自动续签的 reload 钩子仍需配置(如 acme.sh 的 --reloadcmd 重启 v2ray)。