搭建V2Ray服务器是一个分步骤的过程,以下是详细的步骤指南
XVPN加速器面向跨境网络应用打造综合网络加速器2026-08-2210
安装必要工具 确保你的系统已经安装了必要的工具。 在 Ubuntu 上安装 Docker 和 Docker Compose: 更新包仓库:sudo apt update 安装 Docker 和 Docker Compose:sudo apt install docker.io docker-compose 启动并使 Docker 服务自动启动:sudo systemctl start docker sudo systemctl enable docker 创建 Docker 网络 为了避免与其他网络冲突,我们创建一个私有网络。 列出已有的网络接口:ifconfig 假设你有一个新的 eth 接口,设置一个私有IP地址:sudo ip link set eth up sudo dhclient eth 查看新的网络接口:ifconfig eth 记录新的 eth IP地址,如 168.1.100。 启动 V2Ray 服务器 使用 Docker 运行 V2Ray 服务器,我们选择 v2ray/lua 镜像。 运行以下命令: docker run -d --name v2ray-server -e V2RAY_PORT=808 -e V2RAY_LUA=...:.../ -p 808:808 -p 108:108 --restart unless-stopped v2ray/lua V2RAY_PORT=808:指定代理端口。 V2RAY_LUA=...:.../:允许所有地址通过。 -p 808:808 和 -p 108:108:将宿主机端口808和108与容器端口绑定。 检查容器运行状态: docker ps 确认是否有名为 v2ray-server 的容器运行。 配置 V2Ray 客户端 在你的设备上配置 V2Ray 客户端,使用以下配置: 使用 HTTP 代理: v2ray { listen 0... listen 808 protocol "http" proxy "socks5 127...1:108" } 使用 HTTPS...
安装必要工具
确保你的系统已经安装了必要的工具。
在 Ubuntu 上安装 Docker 和 Docker Compose:
- 更新包仓库:
sudo apt update
- 安装 Docker 和 Docker Compose:
sudo apt install docker.io docker-compose
- 启动并使 Docker 服务自动启动:
sudo systemctl start docker sudo systemctl enable docker
创建 Docker 网络
为了避免与其他网络冲突,我们创建一个私有网络。
- 列出已有的网络接口:
ifconfig
- 假设你有一个新的 eth 接口,设置一个私有IP地址:
sudo ip link set eth up sudo dhclient eth
- 查看新的网络接口:
ifconfig eth
- 记录新的 eth IP地址,如
168.1.100。
启动 V2Ray 服务器
使用 Docker 运行 V2Ray 服务器,我们选择 v2ray/lua 镜像。
-
运行以下命令:
docker run -d --name v2ray-server -e V2RAY_PORT=808 -e V2RAY_LUA=...:.../ -p 808:808 -p 108:108 --restart unless-stopped v2ray/lua
V2RAY_PORT=808:指定代理端口。V2RAY_LUA=...:.../:允许所有地址通过。-p 808:808和-p 108:108:将宿主机端口808和108与容器端口绑定。
-
检查容器运行状态:
docker ps
确认是否有名为
v2ray-server的容器运行。
配置 V2Ray 客户端
在你的设备上配置 V2Ray 客户端,使用以下配置:
使用 HTTP 代理:
v2ray {
listen 0...
listen 808
protocol "http"
proxy "socks5 127...1:108"
}
使用 HTTPS 代理:
v2ray {
listen 0...
listen 443
protocol "https"
proxy "socks5 127...1:108"
}
使用 Shadowsocks 反向代理:
v2ray {
protocol "ss"
listen 0...
listen 108
socks "server"
}
将这些配置保存到 ~/v2ray 目录下的配置文件中,v2ray.conf。
启用防火墙
确保宿主机防火墙允许代理流量:
使用 ufw:
- 允许 808 和 108 端口:
sudo ufw allow out 808 sudo ufw allow out 108
- 启用 ufw:
sudo ufw enable
使用 iptables:
- 允许 808 和 108 端口:
sudo iptables -A INPUT -p tcp --dport 808 -j ACCEPT sudo iptables -A INPUT -p tcp --dport 108 -j ACCEPT
- 保存 iptables 设置:
sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
- 在 boot 时加载 iptables:
sudo nano /etc/rc.local
在文件末尾添加:
iptables-restore < /etc/iptables.ipv4.nat
保存并退出。
测试连接
检查代理是否正常工作:
-
测试 HTTP 代理:
curl -I http://127...1:808 2>&1 | grep 200
预期输出类似:
200 OK -
测试 socks5 代理:
curl -I socks5://127...1:108 example.com 2>&1 | grep 200
如果使用 Shadowsocks,可能需要配置 socks5 服务器。
故障排除
V2Ray 服务器出现问题:
-
检查 Docker 日志:
docker logs -l v2ray-server
-
检查网络连接:
ping 127...1
确保宿主机能够访问 localhost。
使用 Docker Compose
为了简化配置,可以使用 Docker Compose。
-
创建
docker-compose.yml文件:version: '3.8' services: v2ray-server: image: v2ray/lua restart: unless-stopped ports: - "808:808" - "108:108" environment: V2RAY_PORT=808 V2RAY_LUA=...:.../ volumes: - ./v2ray:/etc/v2ray networks: - custom_network networks: custom_network: driver: bridge ipam: driver: fixed ips: - 192.168.1.100 -
运行 Docker Compose:
docker-compose up -d
高级配置
根据需要调整配置:
-
启用 TLS: 在配置文件中添加:
tls { enabled true cert_file /etc/ssl/v2ray.pem key_file /etc/ssl/v2ray.key } -
更改协议:
- HTTP:
protocol "http" - HTTPS:
protocol "https" - Shadowsocks:
protocol "ss"
- HTTP:
绕过封锁
V2Ray 被封锁,可能需要:
- 更换协议或 IP 地址。
- 使用域名替代 IP 地址。
- 启用 WebSocket 或其他协议。
通过以上步骤,你已经成功搭建了一个 V2Ray 服务器,根据需要调整配置,确保网络规则和防火墙设置正确,使用 V2Ray 可以帮助你绕过网络限制,访问更多资源。

相关文章







