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

相关推荐
疯狂的程序猴1 天前
构建面向复杂场景的 iOS 应用测试体系 多工具协同下的高质量交付实践
后端
大巨头1 天前
C# 中如何理解泛型
后端
用户992441031561 天前
TRAE SOLO实战录:AI应用可观测性与风险管控的破局之道
后端
Dr丶net1 天前
🔥NestJS 接口文档神器!nestjs-knife4j-plus 让 Swagger 颜值与功能双飞跃
后端
我家领养了个白胖胖1 天前
arthas 我愿称为最强辅助工具
java·后端
今天也很困1 天前
Samba 配置详解
后端
进击的野人1 天前
Node.js文件系统(fs模块)深度解析与实践应用
后端·正则表达式·node.js
前端fighter1 天前
全栈项目:旅游攻略系统
前端·后端·源码
小周在成长1 天前
Java 面相对象继承(Inheritance)指南
后端
该用户已不存在1 天前
一句话让一个AI为我花了(划掉)生成一个APP,Google Antigravity 实操
后端·ai编程·gemini