[OLD] Debian & Ubuntu 上部署 V2Ray 服务端(VMess)

Contents
  1. 1. 注意
    1. 1.1. 准备
    2. 1.2. 安装
    3. 1.3. 配置
    4. 1.4. 防火墙放行
    5. 1.5. 客户端配置文件
    6. 1.6. 相关
    7. 1.7. References

注意

本文的内容已经合并,失效,或已不具有参考价值,请查看给出的重定向链接。

15 秒后自动重定向至: Debian & Ubuntu 搭建部署 sing-box 的 VLESS + Vision + REALITY 服务


本文以 Debian 10 为例,介绍如何部署使用 VMess 协议的 V2Ray 服务端,并说明对应的客户端文件的格式,本文同样完全适用于 Ubuntu 18.04 系统。

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


准备

  • 可用的公网 IP 服务器(例如在 BandwagonHostVultr 等处购买的 VPS)
  • 基础 Linux 操作知识,并了解 vim 编辑器的基本使用方法

编写简易脚本:

1
2
mkdir -p ~/scripts
vim ~/scripts/v2ray.sh

添加如下内容:

~/scripts/v2ray.sh
1
2
3
4
cd ~/scripts
wget https://install.direct/go.sh
sudo bash go.sh
rm -f go.sh*

安装

1
2
sudo chmod -R 400 ~/scripts && chmod 700 ~/scripts
bash ~/scripts/v2ray.sh

配置

Online UUID Generator Tool 上生成一个 UUID 。

编辑配置文件:

1
sudo vim /etc/v2ray/config.json

清空其中内容,添加如下内容,此处示例额外配置了禁止 BT 流量,注意替换其中的 自定义端口号生成的 UUID

/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
{
"log":{
"access": "/var/log/v2ray/access.log",
"error": "/var/log/v2ray/error.log",
"loglevel": "warning"
},
"inbounds": [{
"port": 自定义端口号,
"protocol": "vmess",
"settings": {
"clients": [{
"id": "生成的 UUID",
"alterID": 64
}]
},
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
}
}],
"outbounds": [
{
"protocol": "freedom",
"settings": {}
},
{
"protocol": "blackhole",
"settings": {},
"tag": "blocked"
}
],
"routing": {
"domainStrategy": "IPOnDemand",
"rules": [
{
"type": "field",
"ip": ["geoip:private"],
"outboundTag": "blocked"
},
{
"type": "field",
"protocol": ["bittorrent"],
"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
{
"log": {
"loglevel": "warning"
},
"inbounds": [
{
"tag": "socks",
"port": 10808,
"listen": "127.0.0.1",
"protocol": "socks",
"settings": {
"udp": true
},
"sniffing": {
"enabled": true,
"destOverride": ["http", "tls"]
}
},
{
"tag": "http",
"listen": "127.0.0.1",
"port": 10809,
"protocol": "http",
"settings": {}
}
],
"outbounds": [
{
"protocol": "vmess",
"settings": {
"vnext": [{
"address": "服务器 IP 地址",
"port": 服务器设置的端口,
"users": [{
"id": "服务器使用的 UUID",
"alterId": 64
}]
}]
}
},
{
"protocol": "freedom",
"tag": "direct",
"settings": {}
}
],
"routing": {
"domainStrategy": "IPOnDemand",
"rules": [{
"type": "field",
"ip": ["geoip:private"],
"outboundTag": "direct"
}]
}
}

代理监听在 socks5://127.0.0.1:10808 上,此设置同样可导入 v2rayNG 的 Android 客户端中。

相关

V2Ray + Websocket + TLS + Nginx + Cloudflare 的搭建方法,可参考这篇文章。

发现 UFW 防火墙的日志中包含 V2Ray 服务端口的 [UFW BLOCK] 信息,如果其中 TCP flags 为 ACK RST 等,则可无视,是正常现象。参见 References

References

Project V · Project V 官方网站

UFW occasionally blocking HTTPS (443/TCP) although configured to allow that port on Ubuntu 16.04

Ubuntu UFW blocks port even though it is enabled

Mastodon