Azure Application Gateway – Multisite

Usługa Microsoft Azure Application Gateway oferuje rozwiązanie do równoważenia obciążenia protokołu HTTP, które działa w oparciu o równoważenie obciążenia warstwy 7. Może być wzbogacone o usługę Web Application Firewall, które zabezpieczy witrynę przed atakami takimi jak XSS lub SQL injection.

Usługa jest wyjątkowo opłacalna, gdy porównamy cenę tejże usługi w chmurze z usługami On-Prem, gdzie musimy kupić odpowiedni sprzęt to ceny zaczynają się od 5000 i to dolarów. A tak naprawdę powinniśmy kupić droższe urządzenia i dla zapewnienia HA minimum dwa – w Azure cena przetworzenia 1 TB danych z usługą WAF zamknie się w okolicach 200 dolarów miesięcznie – z czego połowa tejże ceny to opłata za przetwarzanie danych.

Poniżej przedstawię konfigurację Azure Application Gateway, w konfiguracji obsługującej dwie witryny. Założono, że serwer aplikacji IIS mamy już uruchomiony (nota bene na maszynie wirtualnej) i serwuje dwie witryny. Jedną pod adresem głównym – czyli http://10.1.0.4/, a drugą pod /Site2 czyli http://10.1.0.4/Site2/. Nasza docelowa konfiguracja będzie wyglądała jak poniżej:

Przy okazji, jeżeli chcemy coś testować za pomocą SSL i https polecam skorzystać z mojego projektu SSL for Every IP – http://ssl4ip.westeurope.cloudapp.azure.com/ gdzie:

10-0-0-1.h.com.pl resolves to 10.0.0.1

11-1-0-1.h.com.pl resolves to 11.1.0.1

192-168-1-1.h.com.pl resolves to 192.168.1.1

8-8-8-8.h.com.pl resolves to 8.8.8.8

Mamy też dostępny certyfikat z kluczem prywatnym dla *.h.com.pl – a więc możemy mieć dostępne witryny, ala https://192-168-1-1.h.com.pl z zaufanym certyfikatem.

Po kolei w portal Azure wykonujemy:

  1. Tworzymy Application Gateway (Sieć musi mieć dedykowaną podsieć dla obsługi Application Gateway)
  2. Dodaj serwery do pul zaplecza
  3. Tworzymy Listener dla portu 443 – tutaj musimy wgrać certyfikat.

  4. Tworzymy Rules dla protokołu SSL 443

Od tego momentu możemy otwierać strone główną używając adresu IP zarówno wykorzystując http, jak i SSL (https). Możemy dodać odpowiednie wpisy w DNS, aby to robić za pomocą nazw FQDN.

Teraz dokonany konfiguracji obsługujących wiele stron, a płacić będziemy tylko za jednego Application Gateway wraz z jednym wystąpieniem WAF.

  1. Kasujemy utworzony Listener na porcie 443 – gdyż, pierwszy w kolejności musi być obsługujący stronę przez podanego FQDN
  2. Tworzymy Listener dla dedykowanego adresu FQDN:

  3. Gdy potrzeba dodajemy odpowiedni wpis w DNS (CNAME) wskazujący na IP – chyba, że korzystamy z projektu Magic DNS – jak w przykładzie.
  4. Dodajemy Listener dla portu 443 ponownie jak w punkcie 3.
  5. Dodajem HTTP settings, jako przekierowanie na inna witrynę – tutaj można by też używać opcji Override host name:

  6. Następnie dodajemy Basic Rule jak tutaj:

  1. Końcowa praca to dodanie usuniętej wcześniej Rule dla portu 443, czyli:


Azure Application Gateway Service provides an HTTP load balancing solution that is based on layer 7 load balancing. It can include Web Application Firewall, which will secure the site against attacks such XSS or SQL injection.

The Azure service is rather cheap If we compare the price with On-Prem services where we need to buy the right equipment then prices start from 5000 USD. And in fact we should buy more expensive devices to provide HA (two devices) – in Azure the price of processing 1 TB of data with WAF service will close around 200 dollars a month – of which half of the price is a data processing fee.

Below I will introduce the configuration of Azure Application Gateway, in a configuration that supports two sites. Assume that there is a IIS application server with two sites. One at the main address that is http://10.1.0.4/, and the other under /site2 – http://10.1.0.4/Site2/. Our target configuration/solution will look like the following:

By the way, if we want to test something using SSL and HTTPS I recommend to use my project SSL for Every IP- http://ssl4ip.westeurope.cloudapp.azure.com/ Where:

10-0-0-1.h.com.pl resolves to 10.0.0.1

11-1-0-1.h.com.pl resolves to 11.1.0.1

192-168-1-1.h.com.pl resolves to 192.168.1.1

8-8-8-8.h.com.pl resolves to 8.8.8.8

You can also download a certificate with private key for *. h.com.pl – so we can have sites, like https://192-168-1-1.h.com.pl with trusted certificate.

How to configure Application gateway that support multisite:

  1. Create Azure Application Gateway (network must have a dedicated subnet for Application gateway support)
  2. Add servers to backend pools
  3. Create a Listener for port 443 – here we have to upload the certificate:

  4. Create Rules for SSL (443 port):

From this point on, we can open the homepage using an IP address both using HTTP and SSL (HTTPS). We can add the appropriate entries in DNS to do so by using FQDN names.

Let’s do a setup that supports multiple pages, and you will only pay for one Application Gateway along with one WAF instance.

  1. Please delete the created Listener on port 443 – because, first in order must be hosting the page by the given FQDN.
  2. Create a Listener for a dedicated FQDN:

  3. We need to add an appropriate DNS (CNAME) entry pointing to the IP-unless we use the Magic DNS project – as in the example.
  4. Add the Listener for port 443 again as in step 3.
  5. Add HTTP settings as a redirect to another site – you can also use the Override host name option here:

  6. Then we add the Basic Rule as here:

  1. The final work is to add the previously removed Rule for port 443, which is:


Completle solution / Pełne rozwiązanie na screenach: