v2ray ws tls

CentOS/Ubuntu

若是CentOS,则可从EPEL仓库中安装 Nginx

1
2
yum install epel-release
yum install nginx

Cloudflare+namecheap/Freenom

在namecheap或Freenom上注册一个域名,然后修改域名的DNS为cloudflare分配的新的DNS

https://dash.cloudflare.com/profile/api-tokens 创建一个Token。如下

注意,SSL/TLS 还需要设置为 FullFull (strict)

Nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
cat <<EOF>/etc/nginx/conf.d/default.conf
server {
listen 443 ssl;
server_name ${DOMAIN};
ssl_certificate ssl/${DOMAIN}.crt;
ssl_certificate_key ssl/${DOMAIN}.key;

location /ws {
proxy_redirect off;
proxy_pass http://127.0.0.1:10086;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$http_host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_connect_timeout 60s;
proxy_read_timeout 86400s;
proxy_send_timeout 60s;
}
}

v2ray

Server

编辑 /etc/v2ray/config.json 添加以下内容。

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
{
"inbounds": [{
"port": 10086,
"listen":"127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "${UUID}",
"level": 1,
"alterId": 64
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/ws"
}
}
}],
"outbounds": [{
"protocol": "freedom",
"settings": {}
},{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}],
"routing": {
"rules": [
{
"type": "field",
"ip": ["geoip:private"],
"outboundTag": "blocked"
}
]
}
}

其中 id通过 cat /proc/sys/kernel/random/uuid分配

Client

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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
{
"dns": {
"servers": [
"8.8.4.4",
"1.1.1.1",
"8.8.8.8",
"114.114.114.114"
]
},
"inbounds": [
{
"listen": "127.0.0.1",
"port": 15490,
"protocol": "dokodemo-door",
"settings": {
"address": "127.0.0.1"
},
"sniffing": {
}
},
{
"listen": "0.0.0.0",
"port": 8888,
"protocol": "http",
"settings": {
},
"sniffing": {
"enabled": false
}
},
{
"listen": "0.0.0.0",
"port": 1088,
"protocol": "socks",
"settings": {
"auth": "noauth",
"userLevel": 0
},
"sniffing": {
"enabled": false
}
}
],
"log": {
"loglevel": "warning"
},
"outbounds": [
{

"protocol": "vmess",
"sendThrough": "0.0.0.0",
"settings": {
"vnext": [
{
"address": "域名",
"port": 443,
"users": [
{
"alterId": 64,
"id": "服务器UUID",
"level": 0,
"security": "none"
}
]
}
]
},
"streamSettings": {
"dsSettings": {
"path": "/"
},
"httpSettings": {
"host": [
],
"path": "/"
},
"kcpSettings": {
"congestion": false,
"downlinkCapacity": 100,
"header": {
"type": "none"
},
"mtu": 1350,
"readBufferSize": 1,
"tti": 24,
"uplinkCapacity": 5,
"writeBufferSize": 1
},
"network": "ws",
"quicSettings": {
"header": {
"type": "none"
},
"key": "",
"security": ""
},
"security": "tls",
"sockopt": {
"mark": 0,
"tcpFastOpen": false,
"tproxy": "off"
},
"tcpSettings": {
"header": {
"request": {
"headers": {
},
"method": "GET",
"path": [
],
"version": "1.1"
},
"response": {
"headers": {
},
"reason": "OK",
"status": "200",
"version": "1.1"
},
"type": "none"
}
},
"tlsSettings": {
"allowInsecure": true,
"allowInsecureCiphers": false,
"alpn": [
],
"certificates": [
],
"disableSystemRoot": false,
"serverName": ""
},
"wsSettings": {
"headers": {
},
"path": "/ws"
}
},
"tag": "server"
},
{
"protocol": "freedom",
"sendThrough": "0.0.0.0",
"settings": {
"domainStrategy": "AsIs",
"redirect": ":0",
"userLevel": 0
},
"streamSettings": {
"kcpSettings": {
}
},
"tag": "outBound_DIRECT"
},
{
"protocol": "blackhole",
"sendThrough": "0.0.0.0",
"settings": {
"response": {
"type": "none"
}
},
"streamSettings": {
"kcpSettings": {
}
},
"tag": "outBound_BLACKHOLE"
}
],
"policy": {
"system": {
"statsInboundDownlink": true,
"statsInboundUplink": true,
"statsOutboundDownlink": true,
"statsOutboundUplink": true
}
},
"routing": {
"domainStrategy": "AsIs",
"rules": [
{
"ip": [
"geoip:private"
],
"outboundTag": "outBound_DIRECT",
"type": "field"
},
{
"ip": [
"geoip:cn"
],
"outboundTag": "outBound_DIRECT",
"type": "field"
},
{
"domain": [
"geosite:cn"
],
"outboundTag": "outBound_DIRECT",
"type": "field"
}
]
},
"stats": {
}
}

一键配置脚本

整个过程用bash脚本处理

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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/bash

# 域名,自行修改
export DOMAIN=
export UUID=$(cat /proc/sys/kernel/random/uuid)
# cloudflare中创建的token,自行修改
export CF_Token=""

curl -X GET "https://api.cloudflare.com/client/v4/user/tokens/verify" \
-H "Authorization: Bearer ${CF_Token}" \
-H "Content-Type:application/json"

apt install curl wget -y
apt install socat -y
apt install nginx -y

bash <(curl -L -s https://install.direct/go.sh)
cat <<EOF>/etc/v2ray/config.json
{
"inbounds": [{
"port": 10086,
"listen":"127.0.0.1",
"protocol": "vmess",
"settings": {
"clients": [
{
"id": "${UUID}",
"level": 1,
"alterId": 64
}
]
},
"streamSettings": {
"network": "ws",
"wsSettings": {
"path": "/ws"
}
}
}],
"outbounds": [{
"protocol": "freedom",
"settings": {}
},{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}],
"routing": {
"rules": [
{
"type": "field",
"ip": ["geoip:private"],
"outboundTag": "blocked"
}
]
}
}
EOF

# yum -y update
# yum -y install epel-release
# yum -y install nginx

systemctl enable v2ray
systemctl restart v2ray

mkdir /etc/nginx/ssl
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.back
cat <<EOF>/etc/nginx/conf.d/default.conf
server {
listen 443 ssl;
server_name ${DOMAIN};
ssl_certificate ssl/${DOMAIN}.crt;
ssl_certificate_key ssl/${DOMAIN}.key;

location /ws {
proxy_redirect off;
proxy_pass http://127.0.0.1:10086;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host \$http_host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_connect_timeout 60s;
proxy_read_timeout 86400s;
proxy_send_timeout 60s;
}
}
EOF
systemctl stop nginx
systemctl enable nginx

mv ~/.acme.sh ~/.acme.sh.back
curl https://get.acme.sh | sh
source ~/.bashrc
cd ~/.acme.sh
./acme.sh --issue --dns dns_cf -d ${DOMAIN} --standalone -k ec-256
cat ${DOMAIN}_ecc/fullchain.cer >/etc/nginx/ssl/${DOMAIN}.crt
cat ${DOMAIN}_ecc/${DOMAIN}.key>/etc/nginx/ssl/${DOMAIN}.key
systemctl restart nginx
./acme.sh --installcert -d ${DOMAIN} -d *.${DOMAIN} \
--fullchainpath /etc/nginx/ssl/${DOMAIN}.crt \
--keypath /etc/nginx/ssl/${DOMAIN}.key \
--reloadcmd "systemctl force-reload nginx" \
--ecc


echo "DOMAIN: " => ${DOMAIN}
echo "UUID: " => ${UUID}
echo "CF_Token: " => ${CF_Token}


本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!