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

相关推荐
北斗落凡尘12 小时前
LangGraph 入门实战(11)--输出模式
后端·python·langchain
demo007x13 小时前
Hermes-Agent 技术架构
前端·后端·agent
__zRainy__15 小时前
Node系列 · Node基础:net 模块
后端·node.js
Diligently_15 小时前
Anolis 系统更新与密码设置&磁盘扩容
java·后端·spring
kyson_15 小时前
大文件切片上传:从“能传”到“可靠”的 Vue 3 + Java 全栈实现
后端
张龙68715 小时前
uv 全面指南:比 pip 快 100 倍的 Python 包管理器,从安装到团队落地
后端·python
用户409666013175116 小时前
Guava 不止有 Lists 和 Maps:Cache、EventBus、Multimap 实战
java·后端
一只叫煤球的猫17 小时前
从 Java 21 到 Java 25:ThreadLocal 以外的选择—— ScopedValue
java·后端·架构