Redirect HTTP to HTTPS in Azure Application Gateway

Davey Chu picture Davey Chu · Apr 12, 2016 · Viewed 15.1k times · Source

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.

Answer

PotatoFarmer picture PotatoFarmer · Dec 7, 2017

To expand on @jonathan-mas answer,

This can be done using 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 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: https://docs.microsoft.com/en-us/azure/application-gateway/application-gateway-configure-redirect-powershell

AZ CLI Reference: https://docs.microsoft.com/en-us/cli/azure/