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 小时前
Java基础面试题day01
java·开发语言·后端·javase·八股·面向对象编程
用户83562907805112 小时前
Python 设置 Excel 条件格式教程
后端·python·excel
XuCoder12 小时前
告别COS,用 GitHub + jsDelivr 搭建零成本图床
后端
武子康12 小时前
大数据-251 离线数仓 - Airflow 安装部署避坑指南:1.10.11 与 2.x 命令差异、MySQL 配置与错误排查
大数据·后端·apache hive
Memory_荒年12 小时前
自定义 Spring Boot Starter:手搓“轮子”,但要搓出兰博基尼!
java·后端
bugcome_com12 小时前
ASP 与ASP.NET核心解析:从经典 ASP 到ASP.NET的演进与实战
后端·asp.net
栈外12 小时前
我是IDEA重度用户,试了4款AI编程插件:有一款有并发Bug,有一款越用越香
java·后端
小陈同学呦12 小时前
关于如何使用CI/CD做自动化部署
前端·后端
架构师沉默13 小时前
为什么说 Go 做游戏服务器就有人皱眉?
java·后端·架构
echome88813 小时前
Go 语言并发编程实战:用 Goroutine 和 Channel 构建高性能任务调度器
开发语言·后端·golang