反向代理 - Select 路由取决于请求路径
Reverse Proxy - Select route depending on request path
我已经使用 .net Core 5.0 创建了一个反向代理,目前它可以正常工作。现在我想根据请求 URL 更改目的地。这是我的 appsettings.json:
"ReverseProxy": {
"Routes": [
{
"RouteId": "route1",
"ClusterId": "cluster1",
"Match": {
"Path": "{**catch-all}"
}
}
],
"Clusters": {
"cluster1": {
"Destinations": {
"cluster1/destination1": {
"Address": "http://192.168.178.36"
}
}
},
"cluster2": {
"Destinations": {
"cluster1/destination1": {
"Address": "http://localhost:8080/signalr"
}
}
}
}
据我所知,我希望所有请求都转发到我的网络服务器。但是,如果有人使用路径 /signalr 开始请求,那么它应该被转发到我的 signalr 服务器。
我也尝试过使用 google,但据我所知,与 appsettings.json 相关的文档到目前为止真的很差。
我找到了答案,我的新 apssettings.json:
"ReverseProxy": {
"Routes": [
{
"RouteId": "signalrServer",
"ClusterId": "signalrServer",
"Match": {
"Path": "/signalr/{**catch-all}"
}
},
{
"RouteId": "mediaserver",
"ClusterId": "mediaserver",
"Match": {
"Path": "/live/{**catch-all}"
}
},
{
"RouteId": "default",
"ClusterId": "default",
"Match": {
"Path": "{**catch-all}"
}
}
],
"Clusters": {
"default": {
"Destinations": {
"notfound": {
"Address": "http://192.168.178.41/system/error/NotFound"
}
}
},
"mediaserver": {
"Destinations": {
"mediaserver": {
"Address": "http://192.168.178.36"
}
}
},
"signalrServer": {
"Destinations": {
"signalrServer": {
"Address": "http://localhost:8080"
}
}
}
}
我已经使用 .net Core 5.0 创建了一个反向代理,目前它可以正常工作。现在我想根据请求 URL 更改目的地。这是我的 appsettings.json:
"ReverseProxy": {
"Routes": [
{
"RouteId": "route1",
"ClusterId": "cluster1",
"Match": {
"Path": "{**catch-all}"
}
}
],
"Clusters": {
"cluster1": {
"Destinations": {
"cluster1/destination1": {
"Address": "http://192.168.178.36"
}
}
},
"cluster2": {
"Destinations": {
"cluster1/destination1": {
"Address": "http://localhost:8080/signalr"
}
}
}
}
据我所知,我希望所有请求都转发到我的网络服务器。但是,如果有人使用路径 /signalr 开始请求,那么它应该被转发到我的 signalr 服务器。 我也尝试过使用 google,但据我所知,与 appsettings.json 相关的文档到目前为止真的很差。
我找到了答案,我的新 apssettings.json:
"ReverseProxy": {
"Routes": [
{
"RouteId": "signalrServer",
"ClusterId": "signalrServer",
"Match": {
"Path": "/signalr/{**catch-all}"
}
},
{
"RouteId": "mediaserver",
"ClusterId": "mediaserver",
"Match": {
"Path": "/live/{**catch-all}"
}
},
{
"RouteId": "default",
"ClusterId": "default",
"Match": {
"Path": "{**catch-all}"
}
}
],
"Clusters": {
"default": {
"Destinations": {
"notfound": {
"Address": "http://192.168.178.41/system/error/NotFound"
}
}
},
"mediaserver": {
"Destinations": {
"mediaserver": {
"Address": "http://192.168.178.36"
}
}
},
"signalrServer": {
"Destinations": {
"signalrServer": {
"Address": "http://localhost:8080"
}
}
}
}