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

相关推荐
无限大61 天前
《AI观,观AI》:善用AI赋能|让AI成为你深耕核心、推进重心的“最强助手”
前端·后端
uzong1 天前
CoPaw是什么?-- 2026年开源的国产个人AI助手
人工智能·后端
无心水1 天前
【任务调度:框架】11、分布式任务调度进阶:高可用、幂等性、性能优化三板斧
人工智能·分布式·后端·性能优化·架构·2025博客之星·分布式调度框架
pjw198809031 天前
Spring Framework 中文官方文档
java·后端·spring
盒马盒马1 天前
Rust:迭代器
开发语言·后端·rust
( •̀∀•́ )9201 天前
Spring Boot 启动报错 `BindException: Permission denied`
java·spring boot·后端
渔阳节度使1 天前
SpringAI实时监控+观测性
后端·python·flask
Victor3561 天前
MongoDB(42)如何使用$project阶段?
后端
Victor3561 天前
MongoDB(43)什么是嵌入式文档?
后端
Darkdreams1 天前
SpringBoot项目集成ONLYOFFICE
java·spring boot·后端