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

相关推荐
ChaHae-In13 小时前
SpringBoot统一功能处理
java·spring boot·后端
65岁退休Coder15 小时前
LangChain v1.3.4 笔记 - 07 补充:链式调用 LCEL
后端·python·langchain
卷无止境15 小时前
FastAPI 部署在 Nginx 后面到底该怎么配
后端·python
码流怪侠15 小时前
用 WiFi 信号数人头:howmanypeoplearearound 项目深度解析
后端·开源·github
心运软件16 小时前
SpringBoot+ Vue校园社团管理平台的完整架构设计
vue.js·后端
Jodie同志16 小时前
第16~23天:持久化、HITL、流式、MCP与安全
前端·后端·agent
Jodie同志16 小时前
第1~15天:原生Agent、RAG与LangGraph基础(完整代码实操)
前端·后端·agent
Zane199417 小时前
单例线程安全、生产者消费者、死锁:并发面试三连问串讲
java·后端
用户693717500138417 小时前
#DeepSeek+Pi‑Agent 王炸组合跑赢 Claude‑Code!
前端·人工智能·后端