c# - 反向代理 - 根据请求路径选择路由
问题描述
我已经使用 .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 开始一个请求,那么它应该被转发到我的信号器服务器。我也尝试使用谷歌,但据我所知,与 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"
}
}
}
}
推荐阅读
- qt - Qt - 如何使一个线程用于加载纹理和另一个线程用于运行paintGL()
- c++ - Cassandra C++ 驱动程序如何使用 zlib 库?
- java - 过滤数组列表
- r - 使用混合效应模型时的收敛警告
- apache-kafka - 春季云流kafka客户端异常
- html - Angular 6 - 如何在订阅()中停止无限轮询
- autodesk-forge - Autodesk 用户管理 API
- javascript - 当我最小化窗口时,如何控制应该显示图像的哪些部分?
- python - 如何返回字符串向量匹配的numpy矩阵行的索引?
- python - Python 3.7.3 路径和 VS 代码冲突