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

相关推荐
风象南13 小时前
SpringBoot Jar包冲突在线检测
后端
程序员爱钓鱼13 小时前
Go语言实战案例 — 项目实战篇:任务待办清单 Web 应用
后端·google·go
Cyan_RA915 小时前
SpringMVC @RequestMapping的使用演示和细节 详解
java·开发语言·后端·spring·mvc·ssm·springmvc
用户21411832636021 天前
Qwen3-Coder 实战!历史人物短视频一键生成,多分镜人物不崩,魔搭直接玩
后端
追逐时光者1 天前
C#/.NET/.NET Core技术前沿周刊 | 第 54 期(2025年9.8-9.14)
后端·.net
追逐时光者1 天前
C#/.NET/.NET Core编程技巧练习集,配套详细的文章教程讲解!
后端·.net
AD钙奶-lalala1 天前
SpringBoot实现WebSocket服务端
spring boot·后端·websocket
moxiaoran57531 天前
Flask学习笔记(一)
后端·python·flask
你的人类朋友1 天前
🔒什么是HMAC
后端·安全·程序员
盖世英雄酱581361 天前
Read timed out问题 排查
java·数据库·后端