Azure Application Gateway (4) 设置URL路由 - PowerShell

简介:

 《Windows Azure Platform 系列文章目录

 

  本文将介绍如果使用Azure PowerShell,创建Azure Application Gateway URL Routing

  请读者在使用之前,请先查看笔者之前的文章:Azure Application Gateway (3) 设置URL路由,熟悉相关的内容

 

  注意:Azure Application Gateway必须在ARM模式下才可以创建。

  另外PowerShell模式下,和Portal创建的不一样。

  PowerShell模式,并不需要先创建81端口,再创建80端口。PowerShell直接可以使用80端口设置URL Routing

复制代码
#在弹出窗口登录
Login-AzureRmAccount -EnvironmentName AzureChinaCloud

#选择订阅信息
Select-AzureRmSubscription -SubscriptionName "Training"

#先手动创建Resource Group,这里设置Resource Group
$resourcegroupname = 'LeiAppGWRG'

#手动创建Virtual Network
#同之前的文档一样,这个Virtual Network必须要有2个Subnet
$virtualnetworkname= 'LeiAppGatewayVNet'

#设置Application Gateway名称
$appgatewayname = 'LeiAppGateway'

#设置Application Gateway公网IP地址
$publicipname = 'LeiAppGatewayPublicIP'

#Application Gateway 所在的数据中心
$location= 'China East'

#设置端口号
$port=80

$vnet=Get-AzureRmVirtualNetwork -name $virtualnetworkname -ResourceGroupName $resourcegroupname

#Application Gateway加入到第2个Subnet里
$subnet=$vnet.Subnets[1]

$publicip = New-AzureRmPublicIpAddress -ResourceGroupName $resourcegroupname -name $publicipname -location $location -AllocationMethod Dynamic

#Create Application Gateway
$gipconfig = New-AzureRmApplicationGatewayIPConfiguration -Name LeiAppGatewayPublicIP -Subnet $subnet

#设置Backend Pool 1
$pool1 = New-AzureRmApplicationGatewayBackendAddressPool -Name imagesBackendPool -BackendIPAddresses 10.0.0.4,10.0.0.5

#设置Backend Pool 2
$pool2 = New-AzureRmApplicationGatewayBackendAddressPool -Name videosBackendPool -BackendIPAddresses 10.0.0.11,10.0.0.12

#设置Backend Pool 1的会话保持,不保持会话
$poolSetting01 = New-AzureRmApplicationGatewayBackendHttpSettings -Name "imagesSetting" -Port $port -Protocol Http -CookieBasedAffinity Disabled -RequestTimeout 120

#设置Backend Pool 2的会话保持,为保持会话
$poolSetting02 = New-AzureRmApplicationGatewayBackendHttpSettings -Name "videosSetting" -Port $port -Protocol Http -CookieBasedAffinity Enabled -RequestTimeout 240

$fipconfig01 = New-AzureRmApplicationGatewayFrontendIPConfig -Name "frontend1" -PublicIPAddress $publicip

$fp01 = New-AzureRmApplicationGatewayFrontendPort -Name "fep01" -Port $port

$listener = New-AzureRmApplicationGatewayHttpListener -Name "listener01" -Protocol Http -FrontendIPConfiguration $fipconfig01 -FrontendPort $fp01

#设置URL Route,为/images/*
$imagePathRule = New-AzureRmApplicationGatewayPathRuleConfig -Name "pathrule1" -Paths "/images/*" -BackendAddressPool $pool1 -BackendHttpSettings $poolSetting01

#设置URL Route,为/videos/*
$videoPathRule = New-AzureRmApplicationGatewayPathRuleConfig -Name "pathrule2" -Paths "/videos/*" -BackendAddressPool $pool2 -BackendHttpSettings $poolSetting02

#设置DefaultBackendAddressPool
$urlPathMap = New-AzureRmApplicationGatewayUrlPathMapConfig -Name "urlpathmap" -PathRules $videoPathRule, $imagePathRule -DefaultBackendAddressPool $pool1 -DefaultBackendHttpSettings $poolSetting02

$rule01 = New-AzureRmApplicationGatewayRequestRoutingRule -Name "rule1" -RuleType PathBasedRouting -HttpListener $listener -UrlPathMap $urlPathMap

#设置Application Gateway Size为Small,实例个数为1个
$sku = New-AzureRmApplicationGatewaySku -Name "Standard_Small" -Tier Standard -Capacity 1

#开始创建Application Gateway
$appgw = New-AzureRmApplicationGateway -Name $appgatewayname -ResourceGroupName $resourcegroupname  -Location $location -BackendAddressPools $pool1,$pool2 -BackendHttpSettingsCollection $poolSetting01, $poolSetting02 -FrontendIpConfigurations $fipconfig01 -GatewayIpConfigurations $gipconfig -FrontendPorts $fp01 -HttpListeners $listener -UrlPathMaps $urlPathMap -RequestRoutingRules $rule01 -Sku $sku
复制代码

 


本文转自Azure Lei Zhang博客园博客,原文链接:http://www.cnblogs.com/threestone/p/6225961.html,如需转载请自行联系原作者


目录
相关文章
|
3月前
|
数据安全/隐私保护
【Azure Function App】PowerShell Function 执行 Get-AzAccessToken 的返回值类型问题:System.String 与 System.Security.SecureString
将PowerShell Function部署到Azure Function App后,Get-AzAccessToken返回值类型在不同环境中有差异。正常为SecureString类型,但部分情况下为System.String类型,导致后续处理出错。解决方法是在profile.ps1中设置环境变量$env:AZUREPS_OUTPUT_PLAINTEXT_AZACCESSTOKEN=false,以禁用明文输出。
118 0
|
9月前
|
JSON 数据格式
【Azure Fabric Service】演示使用PowerShell命令部署SF应用程序(.NET)
本文详细介绍了在中国区微软云Azure上使用Service Fabrics服务时,通过PowerShell命令发布.NET应用的全过程。由于Visual Studio 2022无法直接发布应用,需借助PowerShell脚本完成部署。文章分三步讲解:首先在Visual Studio 2022中打包应用部署包,其次连接SF集群并上传部署包,最后注册应用类型、创建实例并启动服务。过程中涉及关键参数如服务器证书指纹和服务端证书指纹的获取,并附带图文说明,便于操作。参考官方文档,帮助用户成功部署并运行服务。
310 73
【Azure 应用服务】Azure Powershell Function 出错 The term 'Connect-AzAccount' is not recognized
【Azure 应用服务】Azure Powershell Function 出错 The term 'Connect-AzAccount' is not recognized
149 0
【Azure App Service】PowerShell脚本批量添加IP地址到Web App允许访问IP列表中
Web App取消公网访问后,只允许特定IP能访问Web App。需要写一下段PowerShell脚本,批量添加IP到Web App的允许访问IP列表里!
212 2
|
API 开发者 Python
"FastAPI路由大揭秘!轻松玩转URL映射,让你的Web应用路由设计既RESTful又灵活多变,秒杀传统框架的秘籍在这里!"
【8月更文挑战第31天】在Web开发中,路由是连接用户请求与后端逻辑的关键。FastAPI作为现代Python Web框架的佼佼者,以其简洁的API设计和高性能,提供了高度灵活的路由系统。本文通过开发一个博客系统的案例,详细介绍了FastAPI中路由的实现方法,包括基础路由定义、参数类型验证及路由分组与嵌套等,展示了如何轻松构建RESTful风格的URL映射,提升应用的可维护性和扩展性。
496 2
|
Kubernetes API 网络架构
【Azure APIM】解决APIM Self-hosted Gateway在AKS上,最开始访问时候遇见的404问题
【Azure APIM】解决APIM Self-hosted Gateway在AKS上,最开始访问时候遇见的404问题
191 4
【Azure Durable Function】PowerShell Activity 函数遇见 Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been exceeded.
【Azure Durable Function】PowerShell Activity 函数遇见 Newtonsoft.Json.JsonReaderException: The reader's MaxDepth of 64 has been exceeded.
137 3
【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name
【Azure Web Job】Azure Web Job执行Powershell脚本报错 The term 'Select-AzContext' is not recognized as the name
106 3
【Application Insights】使用Powershell命令向Application Insgihts发送测试数据
【Application Insights】使用Powershell命令向Application Insgihts发送测试数据
112 1
|
数据安全/隐私保护
【Azure Entra ID】使用PowerShell脚本导出Entra ID中指定应用下的所有用户信息
在Azure Entra ID中,需要导出一个Application 下的用户信息, 包含User的创建时间。
229 0