Created
August 21, 2017 23:28
-
-
Save aleksandar-babic/0b7967467c5b91a0745da34c2a4cc33e to your computer and use it in GitHub Desktop.
Azure App Gateway Force HTTPS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the application gateway | |
$gw = Get-AzureRmApplicationGateway -Name DHProductionGatewayFE -ResourceGroupName DeployHandler | |
# Get the existing HTTPS listener | |
$httpslistener = Get-AzureRmApplicationGatewayHttpListener -Name appgatewayhttplistener -ApplicationGateway $gw | |
# Get the existing front end IP configuration | |
$fipconfig = Get-AzureRmApplicationGatewayFrontendIPConfig -Name appgatewayfrontendip -ApplicationGateway $gw | |
# Add a new front end port to support HTTP traffic | |
Add-AzureRmApplicationGatewayFrontendPort -Name appGatewayFrontendPort2 -Port 80 -ApplicationGateway $gw | |
# Get the recently created port | |
$fp = Get-AzureRmApplicationGatewayFrontendPort -Name appGatewayFrontendPort2 -ApplicationGateway $gw | |
# Create a new HTTP listener using the port created earlier | |
Add-AzureRmApplicationGatewayHttpListener -Name appgatewayhttplistener2 -Protocol Http -FrontendPort $fp -FrontendIPConfiguration $fipconfig -ApplicationGateway $gw | |
# Get the new listener | |
$listener = Get-AzureRmApplicationGatewayHttpListener -Name appgatewayhttplistener2 -ApplicationGateway $gw | |
# Add a redirection configuration using a permanent redirect and targeting the existing listener | |
Add-AzureRmApplicationGatewayRedirectConfiguration -Name redirectHttptoHttps -RedirectType Permanent -TargetListener $httpslistener -IncludePath $true -IncludeQueryString $true -ApplicationGateway $gw | |
# Get the redirect configuration | |
$redirectconfig = Get-AzureRmApplicationGatewayRedirectConfiguration -Name redirectHttptoHttps -ApplicationGateway $gw | |
# Add a new rule to handle the redirect and use the new listener | |
Add-AzureRmApplicationGatewayRequestRoutingRule -Name rule02 -RuleType Basic -HttpListener $listener -RedirectConfiguration $redirectconfig -ApplicationGateway $gw | |
# Update the application gateway | |
Set-AzureRmApplicationGateway -ApplicationGateway $gw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment