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

相关推荐
贰先生9 小时前
Xiuno BBS 审计之问题12:HTTPS 请求关闭 SSL 证书校验,存在中间人攻击风险
后端
HZ_YZ10 小时前
清理服务器硬盘脚本
后端
布朗克16810 小时前
Go 入门到精通-16-字符串深入
开发语言·后端·golang·字符串
北冥you鱼10 小时前
Go flag 包详解:从命令行解析到实战应用
开发语言·后端·golang
她说彩礼65万10 小时前
Asp.net core 模型绑定
后端·asp.net
用户342323237631711 小时前
BLE 传感器节点实战
后端
fliter11 小时前
Go 1.26 新增 `bytes.Buffer.Peek`:只看数据,不移动读取位置
后端
时代的狂11 小时前
如何理解 ASP.NET Core 请求生命周期
asp.net·请求生命周期
羑悻11 小时前
我受够了 Coding Agent 的“假聪明,真串行”,于是做了 Meta-Orchestrator!
后端
神奇小汤圆11 小时前
字节二面挂了!被问“订单超时自动取消”
后端