# v2ray 搭建教程

By [晨辰bk](https://paragraph.com/@bk-5) · 2021-12-27

---

### 购买服务器并连接省略不写，不会的自行百度

![image.png](https://storage.googleapis.com/papyrus_images/71f8a0489aef1a9c7bd482b5b6a52e6db6584a58704a1561abbc3cbaebc67bc3.webp)

image.png

UCloud全球大促：[https://www.ucloud.cn/site/active/kuaijiesale.html?invitation\_code=C1x2E6088EA03C6](https://www.ucloud.cn/site/active/kuaijiesale.html?invitation_code=C1x2E6088EA03C6) CDN超值特惠专场：[https://www.ucloud.cn/site/active/cdn-ufile.html?invitation\_code=C1x2E6088EA03C6](https://www.ucloud.cn/site/active/cdn-ufile.html?invitation_code=C1x2E6088EA03C6) 快杰云主机推广：[https://www.ucloud.cn/site/active/ohost.html?invitation\_code=C1x2E6088EA03C6](https://www.ucloud.cn/site/active/ohost.html?invitation_code=C1x2E6088EA03C6)

#### 安装

*   安装wget
    
        sudo yum -y install wget
        
    
*   安装unzip
    
        sudo yum install zip unzip
        
    
*   安装v2ray
    
        bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)
        
    
    *   等待安装完成
        
*   项目地址
    
    [https://github.com/v2fly/v2ray-core](https://github.com/v2fly/v2ray-core)
    
*   安装和更新文档
    
    [https://github.com/v2fly/fhs-install-v2ray](https://github.com/v2fly/fhs-install-v2ray)
    
*   参考网站
    
    [https://www.v2ray.com/](https://www.v2ray.com/)
    

#### 生成UUID

    cat /proc/sys/kernel/random/uuid
    

*   记住生成的这玩意`b72dc422-5813-4a98-98fc-e14c3e9904d8`
    

#### 配置

*   进入config.json
    
        /usr/local/etc/v2ray/config.json
        
    
*   配置如下
    
        {
          "inbounds": [{
            "port": 20001,
            "protocol": "vmess",
            "settings": {
              "clients": [
                {
                  "id": "b72dc422-5813-4a98-98fc-e14c3e9904d8",
                  "level": 1,
                  "alterId": 64
                }
              ]
            }
          }],
          "outbounds": [{
            "protocol": "freedom",
            "settings": {}
          },{
            "protocol": "blackhole",
            "settings": {},
            "tag": "blocked"
          }],
          "routing": {
            "rules": [
              {
                "type": "field",
                "ip": ["geoip:private"],
                "outboundTag": "blocked"
              }
            ]
          }
        }
        
    
*   直接复制我上面的配置即可使用，id就是上面第二步获取的用户id
    
*   此时端口是20001
    
*   ID是b72dc422-5813-4a98-98fc-e14c3e9904d8
    

### 启动

*   在首次安装完成之后，V2Ray 不会自动启动，需要手动运行上述启动命令
    
        ## 启动
        sudo systemctl start v2ray
        
        ## 停止
        sudo systemctl stop v2ray
        
        ## 重启
        sudo systemctl restart v2ray
        
    

### 客户端使用

*   windows
    
    *   【v2rayN-v2rayN.exe-Github Release】 [https://github.com/2dust/v2rayN/releases](https://github.com/2dust/v2rayN/releases)
        
    *   【v2ray-windows-64.zip Github Release】 [https://github.com/v2ray/v2ray-core/releases](https://github.com/v2ray/v2ray-core/releases)
        
*   Android
    
    *   需要你去网上找设备相应的CPU架构并进行选择下载，也可以选择“universal”通用版的，但它却要比其它的安装包大个两倍多，难免会有些臃肿）
        
    *   [https://github.com/2dust/v2rayNG/releases](https://github.com/2dust/v2rayNG/releases)
        
*   macos
    
    *   （Debian、Ubantu、CentOS等电脑桌面发行版（不能完全通用，可以尝试一下））
        
    *   [https://github.com/jiangxufeng/v2rayL/releases](https://github.com/jiangxufeng/v2rayL/releases)
        
*   ios
    
    *   需要国外账号，推荐shadowrocket（小火箭），quantumult（圈），kitsunebi
        

### 工具列表

**图形客户端**

> V2RayW

*   V2RayW 是一个基于 V2Ray 内核的 Windows 客户端。用户可以通过界面生成配置文件，并且可以手动更新 V2Ray 内核。下载：[GitHub](https://github.com/Cenmrev/V2RayW)
    

> V2RayN

*   V2RayN 是一个基于 V2Ray 内核的 Windows 客户端。下载：[GitHub](https://github.com/2dust/v2rayN)
    

> Clash for Windows

*   下载：[GitHub](https://github.com/Fndroid/clash_for_windows_pkg)
    

> V2RayX

*   V2RayX 是一个基于 V2Ray 内核的 Mac OS X 客户端。用户可以通过界面生成配置文件，并且可以手动更新 V2Ray 内核。V2RayX 还可以配置系统代理。下载：[Github](https://github.com/Cenmrev/V2RayX)
    

> V2RayU

*   V2rayU,基于v2ray核心的mac版客户端,界面友好,使用swift4.2编写,支持vmess,shadowsocks,socks5等服务协议,支持订阅, 支持二维码,剪贴板导入,手动配置,二维码分享等。下载：[GitHub](https://github.com/yanue/V2rayU)
    

> V2RayC

*   下载：[GitHub](https://github.com/gssdromen/V2RayC)
    

> ClashX

*   下载：[GitHub](https://github.com/yichengchen/clashX)
    

> Qv2ray

*   Qv2ray：使用 Qt 编写的 v2ray 跨平台 GUI （MacOS, Windows, Linux）支持连接导入和编辑，中英文切换
    
*   下载：[GitHub](https://github.com/lhy0403/Qv2ray)
    
*   官网：[https://lhy0403.github.io/Qv2ray](https://lhy0403.github.io/Qv2ray)
    

> Mellow

*   Mellow 是一个基于规则的全局透明代理工具，可以运行在 Windows、macOS 和 Linux 上，也可以配置成路由器透明代理或代理网关，支持 SOCKS、HTTP、Shadowsocks、VMess 等多种代理协议。
    
*   Download: [Github](https://github.com/mellow-io/mellow)
    

> Kitsunebi

*   Kitsunebi 是一个基于 V2Ray 核心的移动平台应用 (iOS, Android)。它可以创建基于 VMess 或者 Shadowsocks 的 VPN 连接。Kitsunebi 支持导入和导出与 V2Ray 兼容的 JSON 配置。
    
*   由于使用 V2Ray 核心，Kitsunebi 几乎支持 V2Ray 的所有功能，比如 Mux 和 mKCP。
    
*   下载：[iTunes](https://itunes.apple.com/us/app/kitsunebi-proxy-utility/id1446584073?mt=8) | [Play Store](https://play.google.com/store/apps/details?id=fun.kitsunebi.kitsunebi4android&hl=en_US)
    

> i2Ray

*   i2Ray 是另一款基于 V2Ray 核心的iOS应用。界面简洁易用，适合新手用户使用。同时兼容Shadowrocket和Quantumult格式的规则导入。
    

下载：[iTunes](https://itunes.apple.com/us/app/i2ray/id1445270056?mt=8)

> Shadowrocket

*   Shadowrocket 是一个通用的 iOS VPN 应用，它支持众多协议，如 Shadowsocks、VMess、SSR 等。
    
*   下载：[iTunes](https://itunes.apple.com/us/app/shadowrocket/id932747118?mt=8)
    

> Pepi（原名ShadowRay）

*   Pepi 是一个兼容 V2Ray 的 iOS 应用，它可以创建基于 VMess 的 VPN 连接，并与 V2Ray 服务器通信。
    
*   下载：[iTunes](https://itunes.apple.com/us/app/pepi/id1283082051?mt=8)
    

> Quantumult

*   下载：[iTunes](https://itunes.apple.com/us/app/quantumult/id1252015438?mt=8)
    

> BifrostV

*   BifrostV 是一个基于 V2Ray 内核的 Android 应用，它支持 VMess、Shadowsocks、Socks 协议。
    
*   下载：[Play Store](https://play.google.com/store/apps/details?id=com.github.dawndiy.bifrostv) | [APK Pure](https://apkpure.com/bifrostv/com.github.dawndiy.bifrostv)
    

> V2RayNG

*   下载：[Play Store](https://play.google.com/store/apps/details?id=com.v2ray.ang) | [GitHub](https://github.com/2dust/v2rayNG)
    

在线工具/资源
-------

> VeekXT V2Ray配置生成

*   支持 4.x 版本的配置文件生成器 [veekxt.com](https://www.veekxt.com/utils/v2ray_gen)
    

> V2Ray 配置生成器

*   静态 V2Ray 配置文件生成页面 [GitHub](https://github.com/htfy96/v2ray-config-gen)
    

> UUID Generator

*   VMess User ID 生成工具 [uuidgenerator.net](https://www.uuidgenerator.net/)
    

> vTemplate 项目仓库

*   一个 V2Ray 配置文件模板收集仓库 [GitHub](https://github.com/KiriKira/vTemplate)
    

### 配置信息参考

*   [https://toutyrater.github.io/](https://toutyrater.github.io/)
    

### websocket反向代理配置

*   v2ray服务器配置
    
        {
          "inbounds": [
            {
              "port": 20001,
              "protocol": "vmess",
              "settings": {
                "clients": [
                  {
                    "id": "b72dc422-5813-4a98-98fc-e14c3e9904d8",
                    "alterId": 0,
                    "email": ""
                  }
                ],
                "decryption": "none"
              },
              "streamSettings": {
                "network": "ws",
                "security": "none",
                "tlsSettings": {},
                "wsSettings": {
                  "connectionReuse": true,
                  "path": "/blog",
                  "headers": {
                    "Host": "你的域名(需要配置到自己的网站上去)"
                  }
                }
              },
              "tag": "proxy"
            }
          ],
          "outbounds": [
            {
              "protocol": "freedom",
              "settings": {
                "domainStrategy": "UseIP"
              }
            },
            {
              "protocol": "blackhole",
              "settings": {},
              "tag": "blocked"
            }
          ],
          "routing": {
            "settings": {
              "rules": [
                {
                  "inboundTag": [
                    "api"
                  ],
                  "outboundTag": "api",
                  "type": "field"
                },
                {
                  "type": "field",
                  "ip": [
                    "0.0.0.0/8",
                    "10.0.0.0/8",
                    "100.64.0.0/10",
                    "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"
                }
              ]
            },
            "strategy": "rules"
          }
        }
        
    
*   客户端配置
    

![](https://storage.googleapis.com/papyrus_images/c701254220928ee97fc0f251802dfd3f205d2af9e76eaa8493ae6bf18f858017.png)

*   nginx配置中添加如下配置(拦截的相关后缀根据上边的配置自行修改)
    
        location /blog
        {
            proxy_redirect off;
            proxy_pass http://127.0.0.1:20001;
            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;
        }
        
    
*   我使用了https协议进行伪装，自己根据自己的需求进行修改，BT面板可以直接自己进行修改

---

*Originally published on [晨辰bk](https://paragraph.com/@bk-5/v2ray)*
