Debian (Ubuntu) 上部署 V2Ray 服务端

本文以 Debian 9 为例,介绍如何在 Ubuntu 系统上部署 Shadowsocks R 服务端,本文同样完全适用于 Ubuntu 18.04 系统。

注:请先参照 Ubuntu (Debian) 服务器的初始化配置 一文对服务器进行各种必要的配置。本文以 sammy 用户为例,进行 V2Ray 的部署,并默认已按初始化配置文章对服务器进行了配置。


准备

设置脚本:

1
vim ~/.v2ray

添加如下内容:

.v2ray
1
2
3
wget https://install.direct/go.sh
sudo bash go.sh
rm go.sh*

添加执行权限:

1
chmod +x .v2ray

安装

1
bash .v2ray

配置

Online UUID Generator Tool 上生成一个 UUID 。

编辑配置文件:

1
sudo vim /etc/v2ray/config.json

清空其中内容,添加如下内容:

/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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
{
"log":{
"loglevel": "warning",
"access": "/var/log/v2ray/access.log",
"error": "/var/log/v2ray/error.log"
},
"inbounds": [{
"port": 端口,
"protocol": "vmess",
"settings": {
"clients": [{
"id": "填写生成的 UUID",
"level": 1,
"alterID": 64
}]
},
"streamSettings": {
"network": "tcp",
"tcpSettings": {
"header": {
"type": "http",
"response": {
"version": "1.1",
"status": "200",
"reason": "OK",
"headers": {
"Content-Type": ["application/octet-stream", "video/mpeg"],
"Transfer-Encoding": ["chunked"],
"Connection": ["keep-alive"],
"Pragma": "no-cache"
}
}
}
}
}
}],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
},
{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}
],
"routing": {
"domainStrategy": "AsIs",
"rules": [{
"type": "field",
"ip": ["geoip:private"],
"outboundTag": "blocked"
}]
}
}

重启服务:

1
sudo systemctl restart v2ray

防火墙放行

1
sudo ufw allow 端口

至此,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
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
{
"log": {
"loglevel": "warning"
},
"inbounds": [{
"port": 1082,
"listen": "127.0.0.1",
"protocol": "socks",
"settings": {
"udp": true
}
}],
"outbounds": [
{
"protocol": "vmess",
"settings": {
"vnext": [{
"address": "IP 地址",
"port": 端口,
"users": [{
"id": "生成的 UUID",
"alterId": 64
}]
}]
},
"streamSettings": {
"network": "tcp",
"tcpSettings": {
"header": {
"type": "http",
"request": {
"version": "1.1",
"method": "GET",
"path": ["/"],
"headers": {
"Host": ["某个域名"],
"User-Agent": [
"Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36",
"Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46"
],
"Accept-Encoding": ["gzip, deflate"],
"Connection": ["keep-alive"],
"Pragma": "no-cache"
}
}
}
}
}
},
{
"protocol": "freedom",
"tag": "direct",
"settings": {}
}
],
"routing": {
"domainStrategy": "AsIs",
"rules": [{
"type": "field",
"ip": ["geoip:private"],
"outboundTag": "direct"
}]
}
}