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

相关推荐
霸道流氓气质1 小时前
SpringBoot+LangChain4j+Ollama+RAG(检索增强生成)实现私有文档向量化检索回答
java·spring boot·后端
MiNG MENS1 小时前
基于SpringBoot和Leaflet的行政区划地图掩膜效果实战
java·spring boot·后端
IT_陈寒1 小时前
Vite静态资源加载把我坑惨了
前端·人工智能·后端
2601_949814691 小时前
Spring Boot中的404错误:原因、影响及处理策略
java·spring boot·后端
RDCJM1 小时前
Spring Boot spring.factories文件详细说明
spring boot·后端·spring
小码哥_常1 小时前
从ORDER BY RAND()踩坑,看透SQL性能优化
后端
remember_me2 小时前
LangGraph 使用指南
后端
ILYT NCTR2 小时前
搭建Golang gRPC环境:protoc、protoc-gen-go 和 protoc-gen-go-grpc 工具安装教程
开发语言·后端·golang
花椒技术2 小时前
从区间锁到行锁:一次高并发写入死锁治理实战
后端·sql
随风,奔跑2 小时前
Spring Cloud Alibaba(四)---Spring Cloud Gateway
后端·spring·gateway