Table of Contents

安装

提供简单的命令行工具,可以在本地进行相关测试

dotnet tool install --global VKProxy.Cli

不过目前只支持 net9.0 (net10 正式发布后会切换制net10)

安装后可以使用如下命令

vkproxy -h
// it will output
--config (-c)               json file config, like /xx/app.json
--socks5                    use simple socks5 support
--etcd                      etcd address, like http://127.0.0.1:2379
--etcd-prefix               default is /ReverseProxy/
--etcd-delay                delay change config when etcd change, default is 00:00:01
--sampler                   log sampling, support trace/random/none
--memory-cache-max          Memory Cache Size Limit
--memory-cache-percentage   Memory Cache Compaction Percentage
--redis                     StackExchangeRedis config
--redis-pool-size           StackExchangeRedis pool size, default is 10
--redis-data-protection     DataProtection sotre in redis key
--disk-cache                disk cache directory
--disk-cache-max            disk cache Size Limit
--help (-h)                 show all options
View more at https://fs7744.github.io/VKProxy.Doc/docs/introduction.html

如果使用json文件配置

配置项很多,可参考后续具体配置项说明

这里举个例子

创建json文件

{
  "ReverseProxy": {
    "Listen": {
      "http": {
        "Protocols": [
          "Http1"
        ],
        "Address": [
          "127.0.0.1:5001"
        ]
      }
    },
    "Routes": {
      "HTTPTEST": {
        "Match": {
          "Hosts": [
            "*com"
          ],
          "Paths": [
            "/ws*"
          ],
          "Statement": "Method = 'GET'"
        },
        "ClusterId": "apidemo",
        "Timeout": "00:10:11"
      }
    },
    "Clusters": {
      "apidemo": {
        "LoadBalancingPolicy": "RoundRobin",
        "HealthCheck": {
          "Active": {
            "Enable": true,
            "Policy": "Http",
            "Path": "/test",
            "Query": "?a=d",
            "Method": "post"
          }
        },
        "Destinations": [
          {
            "Address": "http://127.0.0.1:1104"
          },
          {
            "Address": "https://google.com"
          }
        ]
      }
    }
  }
}

然后启动

vkproxy -c D:\code\test\proxy\config.json

// 启动后会看到类似如下的内容
info: VKProxy.Server.ReverseProxy[3]
      Listening on: [Key: http,Protocols: HTTP1,EndPoint: 127.0.0.1:5001]
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: D:\code\test\proxy
warn: VKProxy.Server.ReverseProxy[5]
      Active health failed, can not connect socket 127.0.0.1:1104 No connection could be made because the target machine actively refused it. (127.0.0.1:1104).

使用 etcd 配置

在多实例的情况,同一份配置分发就比较麻烦, 这里提供 ui 可以配置etcd + agent 从etcd读取配置 方便大家使用

ui使用可以参考 UI配置站点

用tool 启动 agent 可以这样使用

vkproxy --etcd http://127.0.0.1:2379 --etcd-prefix /ReverseProxy/

// 启动后会看到类似如下的内容
info: VKProxy.Server.ReverseProxy[3]
      Listening on: [Key: http,Protocols: HTTP1,EndPoint: 127.0.0.1:5001]
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
      Content root path: D:\code\test\proxy
warn: VKProxy.Server.ReverseProxy[5]
      Active health failed, can not connect socket 127.0.0.1:1104 No connection could be made because the target machine actively refused it. (127.0.0.1:1104).