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

相关推荐
bcbnb12 分钟前
iOS 文件管理全攻略,多工具协同实现高效调试、数据导出与应用分析
后端
tung tung tung sahur24 分钟前
领略 Rust 抽象之美:自定义迭代器实现全解析
开发语言·后端·rust
用户30745969820724 分钟前
容器(Container)—— 对象的“智能工厂+调度官”
后端·thinkphp
程序猿小蒜1 小时前
基于springboot的校园社团信息管理系统开发与设计
java·前端·spring boot·后端·spring
申阳1 小时前
Day 4:02. 基于Nuxt开发博客项目-整合 Inspira UI
前端·后端·程序员
Mos_x1 小时前
28.<Spring博客系统⑤(部署的整个过程
java·后端
爱淋雨的鼬先生1 小时前
SpringBoot 概述
java·spring boot·后端
血小溅1 小时前
Spring Boot 整合 Spring AI:接入 DeepSeek 与 Ollama 调用大模型
后端·ollama·deepseek
李慕婉学姐1 小时前
Springboot的民宿管理系统的设计与实现29rhm9uh(程序+源码+数据库+调试部署+开发环境)带论文文档1万字以上,文末可获取,系统界面在最后面。
数据库·spring boot·后端
用户3074596982072 小时前
门面(Facade)—— 静态语法的“动态伪装术”
后端·php