Create a custom probe for Azure Application Gateway (classic) by using PowerShell
In this article, you add a custom probe to an existing application gateway with PowerShell. Custom probes are useful for applications that have a specific health check page or for applications that do not provide a successful response on the default web application.
Important
Azure has two different deployment models for creating and working with resources: Resource Manager and Classic. This article covers using the Classic deployment model. Microsoft recommends that most new deployments use the Resource Manager model. Learn how to perform these steps using the Resource Manager model.
Prerequisite: Install the Azure PowerShell module
To perform the steps in this article, you need to install and configure the Azure PowerShell module. Be sure to complete all of the instructions. After the installation is finished, sign in to Azure and select your subscription.
Note
You need an Azure account to complete these steps. If you don't have an Azure account, you can sign up for a free trial.
Create an application gateway
To create an application gateway:
- Create an application gateway resource.
- Create a configuration XML file or a configuration object.
- Commit the configuration to the newly created application gateway resource.
Create an application gateway resource with a custom probe
To create the gateway, use the New-AzureApplicationGateway
cmdlet, replacing the values with your own. Billing for the gateway doesn't start at this point. Billing begins in a later step, when the gateway is successfully started.
The following example creates an application gateway by using a virtual network called "testvnet1" and a subnet called "subnet-1".
New-AzureApplicationGateway -Name AppGwTest -VnetName testvnet1 -Subnets @("Subnet-1")
To validate that the gateway was created, you can use the Get-AzureApplicationGateway
cmdlet.
Get-AzureApplicationGateway AppGwTest
Note
The default value for InstanceCount is 2, with a maximum value of 10. The default value for GatewaySize is Medium. You can choose between Small, Medium, and Large.
VirtualIPs and DnsName are shown as blank because the gateway has not started yet. These values are created once the gateway is in the running state.
Configure an application gateway by using XML
In the following example, you use an XML file to configure all application gateway settings and commit them to the application gateway resource.
Copy the following text to Notepad.
<ApplicationGatewayConfiguration xmlns:i="https://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure">
<FrontendIPConfigurations>
<FrontendIPConfiguration>
<Name>fip1</Name>
<Type>Private</Type>
</FrontendIPConfiguration>
</FrontendIPConfigurations>
<FrontendPorts>
<FrontendPort>
<Name>port1</Name>
<Port>80</Port>
</FrontendPort>
</FrontendPorts>
<Probes>
<Probe>
<Name>Probe01</Name>
<Protocol>Http</Protocol>
<Host>contoso.com</Host>
<Path>/path/custompath.htm</Path>
<Interval>15</Interval>
<Timeout>15</Timeout>
<UnhealthyThreshold>5</UnhealthyThreshold>
</Probe>
</Probes>
<BackendAddressPools>
<BackendAddressPool>
<Name>pool1</Name>
<IPAddresses>
<IPAddress>1.1.1.1</IPAddress>
<IPAddress>2.2.2.2</IPAddress>
</IPAddresses>
</BackendAddressPool>
</BackendAddressPools>
<BackendHttpSettingsList>
<BackendHttpSettings>
<Name>setting1</Name>
<Port>80</Port>
<Protocol>Http</Protocol>
<CookieBasedAffinity>Enabled</CookieBasedAffinity>
<RequestTimeout>120</RequestTimeout>
<Probe>Probe01</Probe>
</BackendHttpSettings>
</BackendHttpSettingsList>
<HttpListeners>
<HttpListener>
<Name>listener1</Name>
<FrontendIP>fip1</FrontendIP>
<FrontendPort>port1</FrontendPort>
<Protocol>Http</Protocol>
</HttpListener>
</HttpListeners>
<HttpLoadBalancingRules>
<HttpLoadBalancingRule>
<Name>lbrule1</Name>
<Type>basic</Type>
<BackendHttpSettings>setting1</BackendHttpSettings>
<Listener>listener1</Listener>
<BackendAddressPool>pool1</BackendAddressPool>
</HttpLoadBalancingRule>
</HttpLoadBalancingRules>
</ApplicationGatewayConfiguration>
Edit the values between the parentheses for the configuration items. Save the file with extension .xml.
The following example shows how to use a configuration file to set up the application gateway to load balance HTTP traffic on public port 80 and send network traffic to backend port 80 between two IP addresses by using a custom probe.
Important
The protocol item Http or Https is case-sensitive.
A new configuration item <Probe> is added to configure custom probes.
The configuration parameters are:
Parameter | Description |
---|---|
Name | Reference name for custom probe. |
Protocol | Protocol used (possible values are HTTP or HTTPS). |
Host and Path | Complete URL path that is invoked by the application gateway to determine the health of the instance. For example, if you have a website http://contoso.com/, then the custom probe can be configured for "http://contoso.com/path/custompath.htm" for probe checks to have a successful HTTP response. |
Interval | Configures the probe interval checks in seconds. |
Timeout | Defines the probe time-out for an HTTP response check. |
UnhealthyThreshold | The number of failed HTTP responses needed to flag the backend instance as unhealthy. |
The probe name is referenced in the <BackendHttpSettings> configuration to assign which backend pool uses custom probe settings.
Add a custom probe to an existing application gateway
Changing the current configuration of an application gateway requires three steps: Get the current XML configuration file, modify to have a custom probe, and configure the application gateway with the new XML settings.
Get the XML file by using
Get-AzureApplicationGatewayConfig
. This cmdlet exports the configuration XML to be modified to add a probe setting.Get-AzureApplicationGatewayConfig -Name "<application gateway name>" -Exporttofile "<path to file>"
Open the XML file in a text editor. Add a
<probe>
section after<frontendport>
.<Probes> <Probe> <Name>Probe01</Name> <Protocol>Http</Protocol> <Host>contoso.com</Host> <Path>/path/custompath.htm</Path> <Interval>15</Interval> <Timeout>15</Timeout> <UnhealthyThreshold>5</UnhealthyThreshold> </Probe> </Probes>
In the backendHttpSettings section of the XML, add the probe name as shown in the following example:
<BackendHttpSettings> <Name>setting1</Name> <Port>80</Port> <Protocol>Http</Protocol> <CookieBasedAffinity>Enabled</CookieBasedAffinity> <RequestTimeout>120</RequestTimeout> <Probe>Probe01</Probe> </BackendHttpSettings>
Save the XML file.
Update the application gateway configuration with the new XML file by using
Set-AzureApplicationGatewayConfig
. This cmdlet updates your application gateway with the new configuration.
Set-AzureApplicationGatewayConfig -Name "<application gateway name>" -Configfile "<path to file>"
Next steps
If you want to configure Transport Layer Security (TLS), previously known as Secure Sockets Layer (SSL) offload, see Configure an application gateway for TLS offload.
If you want to configure an application gateway to use with an internal load balancer, see Create an application gateway with an internal load balancer (ILB).