一、宝塔 v2Ray 服务端部署
1. LNMP 环境部署
- 系统兼容性:
推荐使用Debian 12或Ubuntu 24.04 LTS系统(网页1验证稳定性最佳)# 系统更新 sudo apt update && sudo apt full-upgrade -y --allow-downgrades
- 编译安装优化:
在宝塔「软件商店」选择Nginx 1.28定制编译(网页6建议):./configure --with-http_ssl_module --with-http_v2_module --with-stream
2. v2Ray 协议栈安装
- 多版本部署方案:
# 官方脚本安装(用户提供方案) bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release
laoxiongb2c .sh) # 或Docker容器化部署(网页3优化方案) docker run -d --name v2ray --restart always -p 127.0.0.1:8992:8992 -v /etc/v2ray:/config v2fly/v2fly-core - 配置文件增强:
{ "inbounds": [{ "port": 8992, "protocol": "vmess", "settings": { "clients": [{ "id": "$(openssl rand -hex 16)", // 动态生成UUID "alterId": 64 }] }, "streamSettings": { "network": "ws", "security": "tls", // 强制加密 "wsSettings": { "path": "/cloudflare_proxy" } // 路径伪装 } }] }
3. Nginx 反向代理配置
- SSL证书自动化:
宝塔「计划任务」添加Let’s Encrypt续签:/www/server/panel/pyenv/bin/python3 -u /www/server/panel/class/acme_v2.py --renew_v2=1
- WebSocket流量伪装:
location /cloudflare_proxy { proxy_pass http://127.0.0.1:8992; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; # 防溯源增强(引用网页5的IP隐藏策略) proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; }

4. 启动v2ray
systemctl start v2ray
systemctl enable v2ray
二、服务优化与安全加固
1. BBR加速方案
# 内核参数优化(整合网页6的TCP协议栈)
echo "net.ipv4.tcp_congestion_control = bbr" >> /etc/sysctl.conf
sysctl -p
2. 自动化运维体系
- 日志清理任务:
# 每日清空日志 truncate -s 0 /var/log/v2ray/*.log # 删除7天前历史日志 find /var/log/v2ray/ -name "*.log" -mtime +7 -exec rm -f {} \;

3. 安全防护策略
- Fail2Ban规则配置:
[v2ray-jail] enabled = true port = 8992 filter = v2ray-auth logpath = /var/log/v2ray/error.log maxretry = 3 bantime = 86400

三、卸载 v2ray
先停止 v2ray
systemctl stop v2ray
systemctl disable v2ray
再执行一键移除
bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) --remove
最后记得到 cloudflare 中把云朵点亮,确保 IP 被隐藏了:
打开:https://tool.lu/ip/对结果进行验证:我们看到域名已经放到 cloudfare 代理下边了。
使用本方法可以保证网站和 v2ray 共存,后续还可以在 vps 上继续搭建网站。
四、计划任务
- 时区更改
在宝塔面板 软件商店 >> Linux工具箱 安装,并进行时间更改与同步
/www/server/panel/pyenv/bin/python3 -u /www/server/panel/class/acme_v2.py --renew_v2=1
# 清空日志文件bobyai
echo "" > /var/log/v2ray/access.log
echo "" > /var/log/v2ray/error.log
# 清理缓存目录
rm -rf /var/cache/v2ray/*
# 删除 7 天前的旧日志(可选)
find /var/log/v2ray/ -name "*.log" -mtime +7 -exec rm -f {} \;
[Total: 0 Average: 0]
必须 注册 为本站用户, 登录 后才可以发表评论!