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

相关推荐
金銀銅鐵4 小时前
类实例里还有什么——putfield、getfield 与对象传递
java·jvm·后端
皮皮林5515 小时前
你还在使用 WebSocket 实现实时消息推送吗?
后端
码事漫谈5 小时前
token账单到底要怎么看
后端
Cosolar6 小时前
当 Harness 标准化后,工程师还剩什么?
人工智能·后端·agent
打工仔折腾 AI6 小时前
L3 静态源码取证|工程评测:python-oracledb 驱动评估中的样本偏差陷阱
开发语言·人工智能·后端·python·性能优化
stark张宇7 小时前
分布式事务方案设计与选型思考:消息队列
后端
想不到一个好的ID8 小时前
什么是线程安全
后端
Dreams_l8 小时前
基于SpringBoot实现的抽奖系统(四)
java·spring boot·后端
程序员cxuan8 小时前
阿里又来一王炸,QBot 能组团干活了
人工智能·后端·程序员
用户2339861795738 小时前
TypeScript源码解析:权限系统与 OS 级沙箱
后端