0%

v2ray配置[个人理解]

最近看到这篇的浏览量突然上升了
原因自然你懂得的
但是这篇是没有实质内容的
所以增加一个脚本,快速搭建v2ray+nginx-tls-ws梯子
速度相对kcp来说稍慢,但是胜在安全

v2ray据说是新一代的代理神器,没有用过,只知道相对ss,服务器要求高,而且配置复杂无比.

v2ray没有服务器/客户端区别,只是配置的区别
v2ray配置的整体格式如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"log": {},
"api": {},
"dns": {},
"stats": {},

"routing": {},
"policy": {},

"inbound": {},
"inboundDetour": [],

"outbound": {},
"outboundDetour": [],
"transport": {}
}

json 不支持注释, 评论使用"comment": "",
虽然v2ray开发者有增加注释,实测发现并不能完全解析

配置

log

日志位置以及日志等级

1
2
3
4
5
"log": {
"access": "e:/vmess/log/access.log",
"error": "e:/vmess/log/error.log",
"loglevel": "debug"
},

routing

路由设置,类似firefox的autoproxy/chrome的switchy插件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"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"
}
]
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
"routing": {
"strategy": "rules",
"settings": {
"rules": [
{
"type": "field",
"port": "54-79",
"outboundTag": "direct"
},
{
"type": "field",
"port": "81-442",
"outboundTag": "direct"
},
{
"type": "field",
"port": "444-65535",
"outboundTag": "direct"
},
{
"type": "field",
"domain": [
"gc.kis.scr.kaspersky-labs.com"
],
"outboundTag": "direct"
},
{
"type": "chinasites",
"outboundTag": "direct"
},
{
"type": "field",
"domain": [
"google.com"
],
"outboundTag": "ss_web"
},
{
"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": "direct"
},
{
"type": "chinaip",
"outboundTag": "direct"
}
]
}
}

inbound / inboundDetour

接收传入的数据

inbound是配置主入口,必须有配置
inboundDetour是配置剩余的入口,为列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
"inbound": {
"port": 10086,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "299c53c1-20bf-598b-c97c-771dabb62a21",
"level": 1,
"alterId": 64
}
]
},
"streamSettings": {
"network": "kcp"
},
"detour": {
"to": "vmess-detour-310971"
}
},
"outbound": {
"protocol": "freedom",
"settings": {}
},
"inboundDetour": [
{
"port": 1089,
"protocol": "socks",
"settings": {
"auth": "noauth",
"udp": true,
"ip": "127.0.0.1"
}
},
{
"port": 3128,
"listen": "127.0.0.1",
"protocol": "http",
"settings": {
"timeout": 0
}
},
{
"protocol": "vmess",
"port": "10000-20000",
"tag": "vmess-detour-310971",
"settings": {},
"allocate": {
"strategy": "random",
"concurrency": 5,
"refresh": 5
},
"streamSettings": {
"network": "kcp"
}
},
{
"port": 10087,
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "299c53c1-20bf-598b-c97c-771dabb62a21",
"level": 1,
"alterId": 64
}
]
}
},
{
"protocol": "shadowsocks",
"port": 20001,
"settings": {
"method": "aes-256-cfb",
"password": "dasfdsafdfs",
"udp": true,
"level": 1
}
}
],

outbound / outboundDetour

数据的请求地址

脚本

增加一个快速安装的脚本,但是没有自测过

前提: 将www.example.com域名指向当前的服务器IP

流程是:

  1. 安装/配置v2ray
  2. 安装/配置nginx
  3. 使用certbot生成证书
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/bash

## 配置
## 先设置域名
DOMAIN=www.example.com
UUID=$(cat /proc/sys/kernel/random/uuid)
UUID_ARR=(${UUID//-/ })
UUID_LAST=${UUID_ARR[-1]}

yum install -y epel-release curl git

## 安装v2ray
bash <(curl -L -s https://install.direct/go.sh)
systemctl enable v2ray
cat > /etc/v2ray/config.json << "EOF"
{
"inbounds": [
{
"port": 10000,
"listen":"127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "{UUID}",
"alterId": 64
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/{UUID_LAST}"
}
}
}
],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
}
]
}
EOF
sed -i "s/{UUID}/${UUID}/g" /etc/v2ray/config.json
sed -i "s/{UUID_LAST}/${UUID_LAST}/g" /etc/v2ray/config.json
systemctl restart v2ray

## 安装nginx
yum install -y nginx
systemctl enable nginx

## 弄一个正常的网址
git clone xxxx /data/web/${DOMAIN}

## nginx config
cat > /etc/nginx/conf.d/001_${DOMAIN}.conf << "EOF"
server {
server_name {DOMAIN};
listen 80;

location / {
root /data/web/{DOMAIN};
index index.html index.htm;
}

location /{UUID_LAST} {
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 $http_host;
}
}
EOF
sed -i "s/{DOMAIN}/${DOMAIN}/g" /etc/nginx/conf.d/001_${DOMAIN}.conf
systemctl restart nginx

## 选择Redirect
git clone https://github.com/certbot/certbot.git ~/certbot
cd ~ && ./certbot-auto

echo "[V2RAY]------------------------------"
echo "UUID: ${UUID}"
echo "DOMAIN: ${DOMAIN}"
echo "PORT: 443"
echo "ALTERID: 64"
echo "WS_PATH: /${UUID_LAST}"
echo "[V2RAY]------------------------------"

参考文档

  1. https://www.v2ray.com/chapter_02/