[英]URL Rewrite in Azure Front Door (Preview) Standard/Premium
We have 2 app services: foo.azurewebsites.net
and bar.azurewebsites.net
and have configured origin groups for both sites.我们有 2 个应用程序服务: foo.azurewebsites.net
和bar.azurewebsites.net
并为这两个站点配置了源组。 We would like the front door to do path based routing: ie:我们希望前门进行基于路径的路由:即:
myfd.z01.azurefd.net/foo -> foo.azurewebsites.net
myfd.z01.azurefd.net/bar -> bar.azurewebsites.net
We can configure this to work using Patterns to match
on the routes as /foo/*
and /bar/*
respectively.我们可以将其配置为使用Patterns to match
路由,分别为/foo/*
和/bar/*
。 This works as expected.这按预期工作。
Next, we want to rewrite the URL so that we don't get the initial /foo
or /bar
path sent to the web apps.接下来,我们要重写 URL,这样我们就不会得到发送到 web 应用程序的初始/foo
或/bar
路径。 In other words, the current setup produces the following:换句话说,当前设置产生以下内容:
myfd.z01.azurefd.net/foo/abc -> foo.azurewebsites.net/foo/abc
myfd.z01.azurefd.net/bar/def -> bar.azurewebsites.net/bar/def
What we want is:我们想要的是:
myfd.z01.azurefd.net/foo/abc -> foo.azurewebsites.net/abc
myfd.z01.azurefd.net/bar/def -> bar.azurewebsites.net/def
So we set up a rewrite URL rule as follows:所以我们设置了一个重写 URL 规则如下:
Setting环境 | Value价值 |
---|---|
Action行动 | URL rewrite URL 重写 |
Source pattern来源模式 | /foo/ |
Destination目的地 | / |
Preserve unmatched path保留不匹配的路径 | Yes |
However, this does not appear to work.但是,这似乎不起作用。 In the AzureDiagnostics
logs we can see the rule is firing, but the URL is not being rewritten - it still contains /foo/
.在AzureDiagnostics
日志中,我们可以看到规则正在触发,但 URL 没有被重写 - 它仍然包含/foo/
。 Is there something we are missing?我们缺少什么吗?
I came across the same issue and after some experiments I derive the following behavior for the current state of the Azure Front Door (Preview) Standard/Premium:我遇到了同样的问题,经过一些实验后,我得出了 Azure Front Door(预览版)标准版/高级版的当前 state 的以下行为:
If in the Endpoint Manager a Route is configured to match a sub path, eg /foo/*
, to route to a specific Origin, an enabled UrlRewrite Rule is only applied for the path which is following /foo
.如果在端点管理器中路由被配置为匹配子路径,例如/foo/*
,以路由到特定源,则启用的 UrlRewrite 规则仅适用于/foo
之后的路径。 eg例如
Route:
Pattern to match: /foo/*
OriginGroup: Foo
Rule: UrlRewrite
Source pattern "/"
Destination "/bar/"
Preserve unmatched path: true
will result in a rewrite from eg /foo/baz
to /foo/bar/baz
and thus will not work for the given issue.将导致从例如/foo/baz
重写为/foo/bar/baz
,因此不适用于给定的问题。 However, there are two options to accomplish the desired result.但是,有两种选择可以实现所需的结果。
The Origin path overwrites the Pattern to match and is thus itself already an UrlRewrite. Origin 路径会覆盖要匹配的 Pattern,因此它本身已经是一个 UrlRewrite。 Nevertheless, via the Azure Portal UI it is not allowed to set only /
as path, but via the az afd route update
CLI it is possible and works:尽管如此,通过 Azure 门户 UI 不允许仅设置/
作为路径,但通过az afd route update
CLI 可以并且有效:
Update 2022 - you can now also set '/' as origin path via Azure Portal 2022 年更新- 您现在还可以通过 Azure 门户将“/”设置为原始路径
No extra Rules are required here.这里不需要额外的规则。
Only one Route is configured matching all requests /*
and serving a default Origin.只有一个路由配置匹配所有请求/*
并服务于默认来源。 To this route a Rule set is applied which contains for each origin an Origin group overwerite and a * Url rewrite* rule:此路由应用了一个规则集,其中包含每个来源的来源组覆盖和 * Url 重写* 规则:
You do not need to use rewrite for this, just use simple forwarding with a route rule to match your pattern and forward to respective back end pools您不需要为此使用重写,只需使用带有路由规则的简单转发来匹配您的模式并转发到相应的后端池
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.