v2ray 是一个Go语言写的支持多种协议的代理平台,特点是Vmess协议和支持WebSocket连接。缺点就是配置复杂,没有互联网基础和Linux基础不容易搞定。V2Ray仍处于开发状态,但是核心已经可以稳定使用了。
V2Ray的配置格式是JSON,这种格式的缺点就是嵌套层次太多,大小写敏感。推荐使用JSON 在线解析 查看格式错误。
官方文档写的零碎,没有基于使用场景的配置。而且V2Ray的配置灵活,也不可能把所有配置都列出来。需要自己了解相关知识才能有目的的配置使用。
我尝试的配置组合为Nginx, TLS, Vmess, WebSocket, 使用Nginx是因为TLS加密,使用WebSocket的原因是可以与Web服务共享443端口。参考WebSocket+TLS+Web。这种配置也可以使用在一些Pass平台,比如红帽的OpenShift。
安装过程推荐Linux 安装脚本。请仔细阅读,如有需要,请加上-p 或 --proxy: 使用代理服务器来下载 V2Ray 的文件,格式与 curl 接受的参数一致,比如 socks5://127.0.0.1:1080
或 http://127.0.0.1:3128
。
下面是基于V2Ray自带的配置修改而来客户端配置
{
"log": {
"loglevel": "warning"
},
"inbound": {
"port": 1080,
"listen": "127.0.0.1",
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": false,
"ip": "127.0.0.1"
}
},
"outbound": {
"protocol": "vmess",
"settings": {
"vnext": [
{
"address": "marskid.net",
"port": 443,
"users": [
{
"id": "********-****-****-****-************",
"alterId": 64,
"security": "auto"
}
]
}
]
},
"mux": {
"enabled": false
},
"streamSettings": {
"network": "ws",
"security": "tls",
"tlsSettings": {
"serverName": "marskid.net",
"allowInsecure": true
},
"wsSettings": {
"path": "/ray"
}
}
},
"outboundDetour": [
{
"protocol": "freedom",
"settings": {},
"tag": "direct"
}
],
"dns": {
"servers": [
"8.8.8.8",
"8.8.4.4",
"localhost"
]
},
"routing": {
"strategy": "rules",
"settings": {
"domainStrategy": "IPIfNonMatch",
"rules": [
{
"type": "field",
"port": "1-52",
"outboundTag": "direct"
},
{
"type": "field",
"port": "54-79",
"outboundTag": "direct"
},
{
"type": "field",
"port": "81-442",
"outboundTag": "direct"
},
{
"type": "field",
"port": "444-65535",
"outboundTag": "direct"
},
{
"type": "field",
"domain": ["geosite:cn"],
"outboundTag": "direct"
},
{
"type": "field",
"ip": [
"0.0.0.0/8",
"10.0.0.0/8",
"100.64.0.0/10",
"127.0.0.0/8",
"169.254.0.0/16",
"172.16.0.0/12",
"192.0.0.0/24",
"192.0.2.0/24",
"192.168.0.0/16",
"198.18.0.0/15",
"198.51.100.0/24",
"203.0.113.0/24",
"::1/128",
"fc00::/7",
"fe80::/10",
"geoip:cn"
],
"outboundTag": "direct"
}
]
}
}
}
服务端使用了Nginx和V2Ray的Docker镜像。SSL证书使用Let’s Encrypt自动生成。
Nginx 配置
location /ray {
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_pass http://v2ray_upstream;
}
其中v2ray_upstream
要根据config.json和Docker开放的IP和端口确定
V2Ray服务端配置/etc/v2ray/config.json
{
"log" : {
"access": "/var/log/v2ray/access.log",
"error": "/var/log/v2ray/error.log",
"loglevel": "warning"
},
"inbound": {
"port": 1080,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "********-****-****-****-************",
"level": 1,
"alterId": 64
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/ray"
}
}
},
"outbound": {
"protocol": "freedom",
"settings": {}
},
"outboundDetour": [
{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}
],
"routing": {
"strategy": "rules",
"settings": {
"rules": [
{
"type": "field",
"ip": [
"0.0.0.0/8",
"10.0.0.0/8",
"100.64.0.0/10",
"127.0.0.0/8",
"169.254.0.0/16",
"172.16.0.0/12",
"192.0.0.0/24",
"192.0.2.0/24",
"192.168.0.0/16",
"198.18.0.0/15",
"198.51.100.0/24",
"203.0.113.0/24",
"::1/128",
"fc00::/7",
"fe80::/10"
],
"outboundTag": "blocked"
}
]
}
}
}
Docker启动脚本
#!/bin/bash
docker run -d --restart=always --name v2ray -v /etc/v2ray:/etc/v2ray --expose=1080 v2ray/official
docker ps -a
搭建总共耗时两天,客户端放在树莓派上,将inbound->listen
监听地址127.0.0.1改为0.0.0.0开放给局域网使用。同一网段内的电脑可以使用树莓派的代理服务。比如树莓派的IP为192.168.31.10,那么IP为192.168.31.100的电脑可以设置代理服务器的地址为192.168.31.10,端口1080,协议为Socks5。
{
"inbound": {
"port": 1080,
"listen": "0.0.0.0",
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": false,
"ip": "127.0.0.1"
}
}
}