net core-反向代理

推荐使用框架:Yarp.ReverseProxy,微软开源的框架

一基本使用

var builder = WebApplication.CreateSlimBuilder(args);
builder.Services.AddReverseProxy()
    .LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
 
var app = builder.Build();

app.MapReverseProxy();

app.Run();

appsettings.json

 "ReverseProxy":{
    "Routes":{
      "ROUTE_NAME":{
        "ClusterId": "yarp", 
        "Match": { 
          "Path": "{**catch-all}"
        }
      }
    },
    "Clusters":{
      "yarp": { 
        "LoadBalancingPolicy": "RoundRobin", 
        "Destinations": { 
            "microsoft": { 
              "Address": "https://docs.microsoft.com/zh-cn/" 
            },
            "github":{ 
              "Address": "https://github.com/" 
            } 
        } 
      }
    }
  },

启动项目,发现可以自动调整到github官网上。

------------------分割线-------------------------------------

其他功能待续。

 

posted @ 2023-07-17 15:15  vba是最好的语言  阅读(71)  评论(0编辑  收藏  举报