deploy v2ray proxy service.

Installation

download script of install v2ray

安裝和更新 V2Ray

// 安裝執行檔和 .dat 資料檔
# bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh)

安裝最新發行的 geoip.dat 和 geosite.dat

// 只更新 .dat 資料檔
# bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-dat-release.sh)

移除 V2Ray

# bash <(curl -L https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh) --remove

从本地压缩包安装v2ray

download v2ray-core

install-release.sh --local /path/to/v2ray-linux-64_v4.31.0.zip

Server Side

nginx server

edit nginx.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
......

stream {
  # 将服务端口作为upstream
  upstream guest {
    server localhost:34567;
  }
  # 使用upstream进行限流
  server {
    listen 34568;
    proxy_upload_rate 300k;
    proxy_download_rate 300k;
    proxy_pass guest;
  }
}

......

edit /etc/nginx/site-available/my.site.com

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
......

  # selfuse no limit
  location /myself {
    if ($http_upgrade != "websocket" ) {
      return 404;
    }
    proxy_redirect off;
    proxy_pass http://127.0.0.1:12345;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $http_host;
    # Show real IP in v2ray access.log
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  }

......

v2ray service

edit /usr/local/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
57
58
59
60
61
62
63
64
65
66
{
    "inbounds": [
        {
			"tag": "selbst",
            "port": 55555,
            "listen": "127.0.0.1",
            "protocol": "vless",
            "settings": {
                "decryption": "none",
                "clients": [
                    {
                        "id": "aaaaaaaa-ae50-aaaa-a7c3-1a121db9e72f",
                        "alterId": 64,
                        "level": 0
                    }
                ]
            },
            "streamSettings": {
                "network": "ws",
                "wsSettings": {
                    "path": "/myself"
                }
            }
        }
    ],
    "outbounds": [
        {
            "tag": "IP4_direct",
            "protocol": "freedom",
            "settings": {
                "domainStrategy": "UseIPv4"
            }
        },
        {
            "tag": "IP6_wgcf",
            "protocol": "freedom",
            "settings": {
                "domainStrategy": "UseIPv6"
            }
        }
    ],
    "routing": {
        "settings": {
            "rules": [
                {
                    "type": "field",
                    "inboundTag": "selbst",
                    "outboundTag": "IP6_wgcf",
                    "domain": [
                        "chat.openai.com"
                    ]
                },
                {
                    "type": "field",
                    "inboundTag": [
                        "selbst",
                        "guest_use"
                    ],
                    "outboundTag": "IP4_direct",
                    "network": "tcp,udp"
                }
            ]
        },
        "strategy": "rules"
    }
}

Client Side

 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
{
  "inbounds": [
    {
      "port": 1080,
      "listen": "127.0.0.1",
      "protocol": "socks",
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ]
      },
      "settings": {
        "auth": "noauth",
        "udp": true
      }
    },
    {
      "port": 8889,
      "listen": "127.0.0.1",
      "protocol": "http",
      "sniffing": {
        "enabled": true,
        "destOverride": [
          "http",
          "tls"
        ]
      },
      "settings": {
        "auth": "noauth",
        "udp": false
      }
    }
  ],
  "outbounds": [
    {
      "protocol": "vless",
      "settings": {
        "vnext": [
          {
            "address": "my.site.com",
            "port": 12888,
            "users": [
              {
                "encryption": "none",
                "id": "aaaaaaaa-aaaa-aaaa-a7c3-1a121db9e72f",
                "level": 0
              }
            ]
          }
        ]
      },
      "streamSettings": {
        "network": "ws",
        "security": "tls",
        "wsSettings": {
          "path": "/myself"
        }
      }
    }
  ]
}