Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect HTTP to HTTPS in Azure Application Gateway

I have configured an Application Gateway (AG) to do SSL termination/offload. The AG is configured to only listen on port 443 for HTTPS connections. Is it possible to redirect HTTP to HTTPS without having to:

  • Create a new VM that contains a webserver that redirects the traffic and configure AG to listen on port 80 with the new VM in its backend pool, or
  • Also allow HTTP connections to my application VM's and handle redirect in my application code

I'm hoping I overlooked a flag/feature in AG.

like image 503
Davey Chu Avatar asked Apr 12 '16 14:04

Davey Chu


1 Answers

To expand on Jonathan Mast's answer,

This can be done using the command line only (as of Dec 2017). I don't prefer the Powershell approach (limited portability), I prefer AZ CLI as it is more direct in answering this question.

  1. Create a listener for your HTTP traffic (e.g. FE-HTTP-80-Site). This can be done using Azure portal or CLI.

  2. Create a listener for your HTTPS traffic (e.g. FE-HTTPS-443-Site). This can be done in the Azure portal or CLI.

  3. Create a redirect configuration:

az network application-gateway redirect-config create \
--gateway-name AppGateway \
-g RSgroupAppGateway \
-n Redirect-Site-toHTTPS \
--type Permanent \
--include-path true \
--include-query-string true \
--target-listener FE-HTTPS-443-Site
  1. Create a rule for the HTTP traffic:
az network application-gateway rule create \
--gateway-name AppGateway \
-g RSgroupAppGateway \
-n Rule-HTTP-80-Site \
--rule-type Basic \
--http-listener FE-HTTP-80-Site \
--redirect-config Redirect-Site-toHTTPS

Reference on Concept: Create an application gateway with URL path-based redirection using Azure PowerShell

AZ CLI Reference: Azure Command-Line Interface (CLI) documentation

like image 71
PotatoFarmer Avatar answered Sep 20 '22 17:09

PotatoFarmer