如何在Linux云服务器上配置V2Ray?
Linux云服务器V2Ray配置全指南:从零搭建科学上网环境
在当今网络环境中,V2Ray凭借其出色的混淆能力和稳定的连接性能,已成为科学上网的热门工具。本教程将手把手教你如何在Linux云服务器上部署V2Ray服务端,并配置完整的传输方案。
一、准备工作
在开始前,请确保您已准备好:
- 一台Linux云服务器(推荐Ubuntu 20.04/CentOS 7+)
- SSH连接工具(如PuTTY或Termius)
- 已解析到服务器IP的域名(可选但推荐)
- root或sudo权限
二、安装V2Ray核心
推荐使用官方一键安装脚本:
bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
安装完成后检查服务状态:
systemctl status v2ray
三、配置服务器端
编辑配置文件 /usr/local/etc/v2ray/config.json:
{
"inbounds": [{
"port": 443,
"protocol": "vmess",
"settings": {
"clients": [{
"id": "自动生成的UUID",
"alterId": 64
}]
},
"streamSettings": {
"network": "ws",
"security": "tls",
"wsSettings": {
"path": "/yourpath"
}
}
}],
"outbounds": [{
"protocol": "freedom",
"settings": {}
}]
}
四、SSL证书配置(HTTPS加密)
使用acme.sh申请Let's Encrypt证书:
curl https://get.acme.sh | sh
acme.sh --issue -d yourdomain.com --standalone
安装证书到V2Ray目录:
acme.sh --install-cert -d yourdomain.com \
--key-file /usr/local/etc/v2ray/key.pem \
--fullchain-file /usr/local/etc/v2ray/cert.pem
五、防火墙配置
开放相关端口(以UFW为例):
ufw allow 443/tcp
ufw allow 80/tcp # 证书续期需要
ufw enable
高级配置技巧
1. 多用户配置
在"clients"数组中添加多个用户配置:
"clients": [
{
"id": "UUID1",
"alterId": 64,
"email": "user1@domain.com"
},
{
"id": "UUID2",
"alterId": 64,
"email": "user2@domain.com"
}
]
2. 流量伪装(WebSocket + TLS + Nginx)
通过Nginx反向代理实现更自然的流量特征:
location /yourpath {
proxy_pass http://127.0.0.1:10000;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
}
常见问题排查
Q:客户端无法连接
• 检查服务器防火墙设置
• 确认V2Ray服务正在运行:systemctl status v2ray
• 查看日志:journalctl -u v2ray -f
Q:速度慢
• 尝试更换传输协议(如TCP改为WebSocket)
• 检查服务器带宽限制
• 使用BBR加速:wget -N --no-check-certificate "https://raw.githubusercontent.com/chiakge/Linux-NetSpeed/master/tcp.sh" && chmod +x tcp.sh && ./tcp.sh
最佳实践建议
- 定期更新V2Ray核心:
bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) - 每月自动续期SSL证书:
acme.sh --renew -d yourdomain.com --force - 使用V2RayN/V2RayNG等成熟客户端
- 重要数据建议配合WireGuard等VPN使用
