使用Azure应用程序网关修改/截断基于路径的路由中的路径

时间:2018-01-05 20:23:10

标签: azure reverse-proxy azure-application-gateway

假设应用程序网关收到请求http://contoso.com/images并配置为将其转发到backendserver.contoso.com。使用基于路径的路由规则(例如/images/*)。

我希望应用程序网关不要在请求URL中保留/images路径。我需要将其截断,在这种情况下,请求将只是http://contoso.com//images之后的任何路径都将保持完整。

有可能吗?任何帮助/线索都非常感谢。

2 个答案:

答案 0 :(得分:2)

是的,您今天可以使用PowerShell / CLI执行此操作。在与池关联的后端http设置中,请指定-Path参数。例如 -

Add-AzureRmApplicationGatewayBackendHttpSettings -Path "/" -Name setting1 -Port 80 -Protocol Http -CookieBasedAffinity Disabled 

当根本没有指定-Path时,传入请求将按原样路由到后端 - 这是默认行为。当指定为"/"时,它会从URI中删除匹配的路径。如果指定为非空值,则使用指定的值代替匹配的路径。

答案 1 :(得分:0)

Amsrivas和Stephens的回答是正确的,但是poweshell CLI似乎已经改变了,至少是@ 5.5.0版本,现在你必须使用以下命令来完成这个操作:

# Get gateway object    
$AppGw = Get-AzureRmApplicationGateway -Name "YOUR GATEWAY NAME" -ResourceGroupName "YOUR GATEWAY RESOURCE GROUP"
# Show current settings
Get-AzureRmApplicationGatewayBackendHttpSettings -ApplicationGateway $AppGw
# Set path on local object (other values are whatever you want)
Set-AzureRmApplicationGatewayBackendHttpSettings -ApplicationGateway $AppGw -Name "YOUR SETTING NAME" -Port "80" -Protocol "Http" -CookieBasedAffinity "Disabled" -RequestTimeout 30 -Path "/"
# Commit changes back to Azure
$UpdatedAppGw = Set-AzureRmApplicationGateway -ApplicationGateway $AppGw
# Show new settings as applied in Azure
Get-AzureRmApplicationGatewayBackendHttpSettings -ApplicationGateway $UpdatedAppGw