我可以使用Ocelot API网关代理网站吗



我是Ocelot API网关的新手,正试图弄清楚如何执行响应主机重写?

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

感谢提供的任何帮助

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

有点晚了,但我认为你需要一个"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。

最新更新