asp.net core反向代理

新建项目

新建空白的asp.net core web项目

安装Yarp.ReverseProxy包版本为2.2.0-preview.1.24266.1

编写代码

cs 复制代码
namespace YarpStu01;

public class Program
{
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);
        builder.Services.AddReverseProxy().LoadFromConfig(builder.Configuration.GetSection("ReverseProxy"));
        var app = builder.Build();
        app.MapReverseProxy();
        app.Run();
    }
}

修改appsettings.json

json 复制代码
{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "ReverseProxy": {
    "Routes": {
      "route1": {
        "ClusterId": "cluster1",
        "Match": {
          "Path": "{**catch-all}"
        }
      }
    },
    "Clusters": {
      "cluster1": {
        "Destinations": {
          "destination1": {
            "Address": "http://127.0.0.1:8086"
          }
        }
      }
    }
  }
}


参考

https://microsoft.github.io/reverse-proxy/articles/getting-started.html
https://blog.csdn.net/sD7O95O/article/details/122762268
https://www.cnblogs.com/webenh/p/15660137.html

相关推荐
妙蛙种子3114 小时前
【Java设计模式 | 创建者模式】建造者模式
java·开发语言·后端·设计模式·建造者模式
zihao_tom5 小时前
Spring 简介
java·后端·spring
Java女侠_9年实战5 小时前
Spring框架“惯性思维”坑——@Transactional失效场景、Bean注入循环依赖
后端
Ares-Wang5 小时前
flask》》多线程并发数据安全问题 threading.local werkzeug.local.Local
后端·python·flask
覆东流5 小时前
第2天:Python变量与数据类型
开发语言·后端·python
Rust研习社6 小时前
Rust Default 特征详解:轻松实现类型默认值
开发语言·后端·rust
南囝coding6 小时前
零成本打造专业域名邮箱:Cloudflare + Gmail 终极配置保姆级全攻略
前端·后端
李二毛6 小时前
看到 done=true,就说明前面的写入都可见吗?
后端
Master_Azur6 小时前
JavaEE之Stream流
后端
暮年6 小时前
List并发实现-Vector
后端