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

相关推荐
码事漫谈31 分钟前
Cursor+Graphify实属强强联合了
后端
用户2986985301437 分钟前
不用无头浏览器,Java 如何将 HTML 转成图片?
java·后端
我叫黑大帅1 小时前
其实跨域问题是后端来解决的? CORS
后端·面试·go
掘金一周1 小时前
掘友们,一人说一个你买过夯到爆的东西 | 沸点周刊 4.23
前端·人工智能·后端
Developer_Niuge1 小时前
告别翻不动的 1000+ 书签:开源 Chrome / Edge 浏览器书签管理插件 Smart Bookmark 0.2 发布
前端·后端
ElevenPlus1 小时前
【 AI智能体时代:一名Javaer的技术随想录】MCP服务部署架构
后端
千寻girling2 小时前
RabbitMQ 详细教程(38K字数)
java·后端·面试
Rust研习社2 小时前
Rust 多线程从入门到实战
开发语言·后端·rust
卷毛的技术笔记2 小时前
从“拆东墙补西墙”到“最终一致”:分布式事务在Spring Boot/Cloud中的破局之道
java·spring boot·分布式·后端·spring cloud·面试·rocketmq
袋鱼不重2 小时前
Hermes Agent 直连飞书机器人
前端·后端·ai编程