我需要为 appsettings.json 文件中的 yarp 路径部分定义以下路径的模式:
/Contact/Images/Image.ashx?h=28&id=69865t65-888t-w987-tg7l-j88yt6541uj&w=100&54464454
我在 appsettings.json 文件中的 yarp 配置如下:
"ReverseProxy": {
"Routes": {
"route1": {
"ClusterId": "cluster1",
"Match": {
"Path": ""
}
}
},
"Clusters": {
"cluster1": {
"LoadBalancingPolicy": "RoundRobin",
"Destinations": {
"cluster1/destination1": {
"Address": "https://www.example.com"
}
}
}
}
}
我能做什么?任何帮助将不胜感激。
您可以在“匹配”部分的“路径”字段中添加匹配模式。
{**catch-all}
是一个通配符,可以匹配任何路径。然后在Address中配置目标服务器地址。
在这个例子中:我配置了响应的路由地址,这意味着当有路径匹配
/WeatherForecast/PP/{**catch-all}
的请求时,该请求将被转发到我在Address:中配置的目标api地址
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"ReverseProxy": {
"Routes": {
"route1": {
"ClusterId": "cluster1",
"Match": {
"Path": "/WeatherForecast/PP/{**catch-all}"
}
}
},
"Clusters": {
"cluster1": {
"Destinations": {
"destination1": {
"Address": "https://localhost:7198/"
}
}
}
}
}
}
对应路由节点时:
这将转发到我的目标地址: