0

我是 Ocelot API Gateway 的新手,想弄清楚如何执行响应主机重写?

我的 ocelot api 网关托管在 localhost:5000 上,下游服务器在另一个主机 example.com 上。我可以从 localhost:5000 代理到 example.com,但是,当 example.com 发送响应时,我被重定向到 example.com。我需要留在一个域内(本地主机:5000)。

任何帮助表示赞赏

{
"ReRoutes": [
    {
    "DownstreamPathTemplate": "/example/{all}",
    "DownstreamScheme": "https",
    "DownstreamHostAndPorts": [
        {
            "Host": "example.com",
            "Port": 443
        }
    ],
    "UpstreamPathTemplate": "/example/{all}",
    }
],
"GlobalConfiguration": {
    "BaseUrl": "https://localhost:5000"
 }
}
4

1 回答 1

0

有点晚了,但我认为你需要一个“DownstreamHeaderTransform”,它将 example.com 改回 localhost:9000。(不确定端口是否会正确映射)。在我们的用例中,我们使用下游服务器的 IP 地址,然后将其映射回外部世界看到的主机。对于您,请尝试以下方式:

{
"ReRoutes": [
    {
    "DownstreamPathTemplate": "/example/{all}",
    "DownstreamScheme": "https",
    "DownstreamHostAndPorts": [
        {
            "Host": "example.com",
            "Port": 443
        }
    ],
    "DownstreamHeaderTransform": {
        "Referrer": "https://example.com, https://localhost:5000",
        "Host": "example.com, localhost:9000",
        "Origin": "https://example.com, https://localhost:5000"
    },
    "UpstreamPathTemplate": "/example/{all}",
    }
],
"GlobalConfiguration": {
    "BaseUrl": "https://localhost:5000"
 }
}

就个人而言,我发现 Ocelot 相当挑剔,并会尝试 Kestrel。

于 2021-01-13T07:37:56.833 回答