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

相关推荐
纸月4 分钟前
短信服务(二):实现某短信服务商崩溃后自动切换并重试
后端·go
fenghuo_yuanma2 小时前
如何在IIS6,7中部署ASP.NET网站
后端·asp.net·网站部署
小果子^_^7 小时前
springboot调用wsdl接口
java·spring boot·后端·wsdl
城市的稻草人VS8 小时前
rust 终端显示综合例程
开发语言·后端·rust
ing657689 小时前
基于weixin小程序校园快递系统的设计
java·spring boot·后端·mysql·课程设计
Dragon Wu11 小时前
SpringCloud OpenFeign 踩坑总结
java·spring boot·后端·spring cloud·微服务
椰汁3311 小时前
随机文章生成器:Node.js与JSON数据的创意碰撞
javascript·后端·面试
烦 啊12 小时前
go Channel原理 (三)
开发语言·后端·golang
rayylee12 小时前
Linux OpenSSH爆出高危漏洞
linux·运维·服务器·后端·安全