Home
%3CLINGO-SUB%20id%3D%22lingo-sub-392639%22%20slang%3D%22en-US%22%3ESetting%20up%20Application%20Gateway%20with%20WAF%20with%20an%20App%20Service%20that%20uses%20multiple%20Custom%20Domain%20names%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-392639%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3EFirst%20published%20on%20MSDN%20on%20Jul%2018%2C%202018%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%20%3CSTRONG%3E%20This%20post%20was%20contributed%20by%20Salahuddin%20Khatri.%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CH3%20id%3D%22toc-hId-1485073935%22%20id%3D%22toc-hId-1505418482%22%3ESetting%20up%20Application%20Gateway%20with%20WAF%20with%20an%20App%20Service%20that%20uses%20multiple%20Custom%20Domain%20names%3C%2FH3%3E%3CBR%20%2F%3E%20I%20came%20across%20in%20a%20scenario%20in%20which%20customer%20is%20using%20WordPress%20Multisite%20configuration%20on%20Azure%20App%20Service%20with%20Linux%20(Multitenant)%20and%20publishing%20Azure%20App%20Service%20using%20Application%20Gateway%20to%20utilize%20WAF%20functionality.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Just%20so%20you%20know%20the%20template%20available%20in%20Azure%20Market%20Place%20for%20WordPress%20with%20App%20Service%20on%20Linux%20is%20deployed%20on%20a%20Linux%20container%20and%20you%20cannot%20enable%20Multisite%20feature%20in%20it%20unless%20you%20modify%20the%20container%20and%20then%20deploy%20the%20whole%20container%2C%20I%20have%20decided%20to%20deploy%20the%20App%20Service%20on%20Linux%20and%20then%20installed%20WordPress%20in%20it%20and%20then%20enabled%20Multi%20Site%20feature.%20For%20Those%20who%20doesn%E2%80%99t%20know%20the%20Multi%20site%20feature%20of%20WordPress%2C%20A%20multisite%20network%20is%20a%20collection%20of%20sites%20that%20all%20share%20the%20same%20WordPress%20installation.%20They%20can%20also%20share%20plugins%20and%20themes.%20The%20individual%20sites%20in%20the%20network%20are%20virtual%20sites%20in%20the%20sense%20that%20they%20do%20not%20have%20their%20own%20directories%20on%20your%20server%2C%20although%20they%20do%20have%20separate%20directories%20for%20media%20uploads%20within%20the%20shared%20installation%2C%20and%20they%20do%20have%20separate%20tables%20in%20the%20database%20for%20more%20information%20please%20review%20here%20%3CA%20href%3D%22https%3A%2F%2Fcodex.wordpress.org%2FCreate_A_Network%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fcodex.wordpress.org%2FCreate_A_Network%20%3C%2FA%3E%20.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Just%20to%20let%20you%20know%20what%20are%20we%20going%20to%20do%20in%20this%20article%2C%20we%20will%20go%20through%20step%20by%20step%20where%20we%20are%20going%20to%20use%20Azure%20App%20Service%20(Multitenant)%20with%20multiple%20custom%20domain%20names%20and%20we%20are%20going%20to%20publish%20Azure%20App%20Service%20using%20Application%20Gateway%20with%20WAF%2C%20where%20application%20gateway%20will%20accept%20multiple%20custom%20domain%20names%20and%20will%20forward%20the%20request%20to%20one%20back%20end%20which%20is%20Azure%20App%20Service%20(Multitenant)%2C%20I%20will%20not%20go%20through%20installing%20App%20Service%20and%20installing%20WordPress%20along%20with%20Multisite%20configuration%2C%20as%20this%20is%20a%20unique%20scenario%20I%20thought%20to%20write%20a%20blog%20post%20about%20it.%20%3CBR%20%2F%3E%20Prerequisites%20%3CBR%20%2F%3E%20As%20a%20prerequisite%20there%20is%20nothing%20much%2C%20but%20it%20would%20be%20assumed%20that%20App%20Service%20is%20deployed%20and%20configured%2C%20application%20gateway%20is%20deployed%20but%20not%20configured%20because%20we%20are%20going%20to%20do%20that%20together%20and%20access%20to%20External%20DNS%20%3CBR%20%2F%3E%20Before%20We%20Start!!%20%3CBR%20%2F%3E%20Before%20we%20start%2C%20since%20I%20have%20two%20websites%20which%20I%20want%20to%20access%20using%20Application%20Gateway%2C%20in%20this%20blog%20I%20am%20going%20to%20use%20my%20own%20custom%20domain%20name%20salah.co%20whereas%20kw.salah.co%20and%20pk.salah.co%20will%20be%20subdomain%20names%20added%20and%20verified%20in%20Azure%20App%20Service%20using%20awverify%20and%20CNAME%20record%20will%20be%20pointing%20to%20Application%20gateway%20IP%20Address%20domain%20name.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Ok%20enough%20about%20scenario%20and%20let%20us%20get%20it%20going%20further%20with%20real%20work%20%3CBR%20%2F%3E%20Adding%20Custom%20Domain%20in%20Web%20Apps%20%3CBR%20%2F%3E%20We%20are%20going%20to%20need%20to%20prepare%20the%20App%20Service%20to%20accept%20requests%20on%20the%20custom%20domain%20that%20routes%20through%20the%20Application%20Gateway.%20For%20this%2C%20we%20need%20to%20first%20add%20the%20custom%20domain%20on%20the%20App%20Service.%20You%20can%20follow%20the%20regular%20guide%20to%20configure%20a%20custom%20domain%20by%20using%20awverify%20records%20to%20avoid%20adjusting%20the%20domain%E2%80%99s%20actual%20records%20(%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapp-service%2Fapp-service-custom-domain-name-migrate%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapp-service%2Fapp-service-custom-domain-name-migrate%20%3C%2FA%3E%20)%2C%20since%20our%20purpose%20is%20to%20add%20custom%20domain%20name%20in%20Azure%20and%20for%20that%20we%20have%20to%20use%20awverify%20record%20in%20external%20DNS%20pointing%20to%20App%20Service%20URL%20so%20that%20App%20Service%20will%20allow%20us%20to%20add%20those%20custom%20domain%20names.%20Go%20to%20your%20external%20DNS%20and%20based%20on%20your%20domain%20names%20create%20the%20txt%20records%20pointing%20to%20App%20Service%20URL%2C%20below%20is%20what%20I%20have%20done%20in%20my%20External%20DNS%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101206i40F5D222BDA92778%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Let%20us%20open%20App%20Service%20and%20go%20to%20Custom%20Domain%20option%20and%20click%20on%20%3CB%3E%20Add%20hostname%20%3C%2FB%3E%20to%20add%20the%20required%20domains%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101207iD90EE018848FBC61%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20On%20the%20Add%20hostname%20under%20%3CB%3E%20hostname%20%3C%2FB%3E%20write%20down%20the%20required%20domain%20%3CB%3E%20pk.salah.co%20%3C%2FB%3E%20and%20click%20%3CB%3E%20Validate%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101208i8B1CAE8991AC4728%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20As%20the%20awverify%20txt%20record%20is%20already%20created%2C%20Azure%20App%20Service%20has%20verified%20domain%20ownership%20and%20hostname%20availability%2C%20click%20on%20%3CB%3E%20Add%20hostname%20%3C%2FB%3E%20to%20add%20the%20domain%20name%20in%20Azure%20App%20Service%2C%20do%20the%20same%20for%20your%20other%20domains%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101209iD40BAC698F20773E%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20I%20have%20added%20both%20domains%20in%20Azure%20App%20Service%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101210iF89C057219501EB7%22%20%2F%3E%20%3CBR%20%2F%3E%20Setting%20up%20the%20Application%20Gateway%20%3CBR%20%2F%3E%20Now%20we%20have%20added%20custom%20domains%20in%20Azure%20App%20Service%2C%20let%20us%20configure%20application%20gateway%20with%20WAF%20to%20accept%20custom%20multiple%20domain%20names%20and%20send%20it%20to%20Azure%20App%20Service%2C%20I%20have%20also%20done%20other%20configuration%20in%20Azure%20App%20Service%20with%20WordPress%20and%20Multisite%20configuration%20to%20Map%20the%20domains%20etc.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20We%20are%20going%20to%20use%20the%20mixture%20of%20PowerShell%20and%20GUI%20for%20this%2C%20as%20some%20required%20settings%20we%20need%20to%20set%20are%20only%20available%20in%20PowerShell%20for%20now.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20The%20typical%20guide%20for%20setting%20up%20an%20App%20Service%20behind%20an%20existing%20Application%20Gateway%20is%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapplication-gateway%2Fapplication-gateway-web-app-powershell%23configure-a-web-app-behind-an-existing-application-gateway%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapplication-gateway%2Fapplication-gateway-web-app-powershell%23configure-a-web-app-behind-an-existing-application-gateway%20%3C%2FA%3E%20%2C%20however%20this%20guide%20will%20help%20you%20to%20configure%20the%20application%20gateway%20with%20default%20configuration%20to%20connect%20with%20Azure%20App%20Service%2C%20where%20App%20service%20is%20configured%20with%20one%20custom%20domain%20name%20or%20no%20custom%20domain%20name%20at%20all%2C%20as%20well%20as%20same%20guide%20can%20create%20application%20gateway%20if%20does%20not%20exist%20and%20the%20connect%20with%20Azure%20App%20service%2C%20where%20App%20service%20is%20configured%20with%20one%20custom%20domain%20name%20or%20no%20custom%20domain%20name%20at%20all.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Our%20scenario%20is%20different%2C%20we%20have%20multiple%20custom%20domain%20names%20and%20we%20want%20Application%20Gateway%20to%20accept%20and%20connect%20to%20Azure%20App%20Service%20with%20multiple%20domain%20names%20where%20I%20have%20configured%20Multi%20Site%20with%20WordPress.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Here%20is%20What%20are%20we%20going%20to%20do%2C%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%201.%20We%20will%20create%20an%20application%20gateway%20with%20WAF%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%202.%20We%20will%20configure%20default%20Backend%20pool%20to%20connect%20to%20App%20Service%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%203.%20We%20will%20create%20two%20new%20http%20Settings%20with%20custom%20probe%20one%20for%20each%20domain%2C%20if%20you%20have%20more%20than%20one%20domain%20then%20you%20must%20create%20Http%20Settings%20based%20on%20number%20of%20custom%20domains%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%204.%20We%20will%20create%20two%20multi-site%20listeners%20one%20for%20each%20domain%2C%20if%20you%20have%20more%20then%20one%20domain%20then%20you%20must%20create%20listeners%20based%20on%20number%20of%20custom%20domains%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%205.%20We%20will%20create%20two%20Rules%20one%20for%20each%20Listener%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%206.%20We%20will%20delete%20default%20Application%20Gateway%20settings%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%207.%20We%20will%20run%20commands%20from%20PowerShell%20to%20create%20custom%20Probe%20with%20required%20settings%20to%20make%20it%20work%20for%20App%20service%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%208.%20We%20will%20configure%20Http%20settings%20to%20accept%20and%20work%20for%20custom%20domains%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Create%20Application%20Gateway%20%3CBR%20%2F%3E%20Input%20the%20application%20gateway%20name%2C%20location%20and%20RG%20on%20the%20basic%20information%20blade%2C%20I%20am%20naming%20my%20application%20gateway%20as%20testappgw%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101211i7A52DD2B02427134%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20I%20am%20going%20to%20select%20a%20VNET%20with%20dedicated%20subnet%20for%20application%20gateway%2C%20select%20the%20Public%20IP%20under%20IP%20Address%20type%20and%20then%20select%20create%20new%20Public%20IP%20Address%2C%20define%20the%20name%20for%20the%20DNS%20name%20of%20the%20Public%20IP%20Address%2C%20this%20is%20necessary%20because%20we%20are%20going%20to%20use%20this%20name%20for%20CNAME%20creation%20with%20your%20own%20DNS%2C%20configure%20Listener%20with%20port%2080%20since%20in%20this%20example%20I%20am%20going%20to%20have%20HTTP%20website%2C%20select%20other%20required%20options%20and%20click%20OK%20review%20the%20settings%20and%20then%20click%20ok%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101212iB0AE5C0928350C63%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Since%20the%20application%20gateway%20is%20created%2C%20we%20will%20now%20start%20creating%20HTTP%20Settings%2C%20Multisite%20Listener%20etc%20as%20mentioned%20before%20%3CBR%20%2F%3E%20Editing%20existing%20%2F%20default%20Backend%20pool%20to%20connect%20App%20Service%20%3CBR%20%2F%3E%20On%20the%20Application%20Gateway%20with%20WAF%20Enabled%2C%20click%20on%20%3CB%3E%20Backend%20Pools%20%3C%2FB%3E%20then%20open%20the%20default%20%3CB%3E%20appGatewayBackendPool%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101213iB42C12C4EDB39C3A%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20under%20name%20type%20the%20name%20of%20Azure%20Web%20App%20in%20our%20scenario%20it%20is%20%3CB%3E%20sitewordpressss.azurewebsites.net%20%3C%2FB%3E%20then%20save%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101214i7286703379897221%22%20%2F%3E%20%3CBR%20%2F%3E%20Add%20new%20HTTP%20Settings%20%3CBR%20%2F%3E%20Create%20two%20HTTP%20Settings%2C%20one%20for%20each%20custom%20domain%20name%2C%20if%20you%20have%20more%20custom%20domain%20name%20then%20you%20can%20create%20HTTP%20settings%20based%20on%20the%20number%20of%20domains%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20On%20the%20Application%20Gateway%20with%20WAF%20Enabled%2C%20click%20on%20%3CB%3E%20HTTP%20Settings%20%3C%2FB%3E%20then%20click%20on%20%3CB%3E%20Add%20%3C%2FB%3E%20%2C%20we%20will%20delete%20the%20default%20one%20once%20all%20dependencies%20are%20deleted.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101215iA5982FE6377008AE%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20On%20the%20Add%20HTTP%20Settings%2C%20fill%20the%20fields%2C%20as%20per%20my%20scenario%20I%20do%20not%20need%20other%20settings%20to%20be%20enabled%2C%20changed%20Request%20timeout%20to%20%3CB%3E%2030%20%3C%2FB%3E%20as%20per%20requirements.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101216iA9B5C37D8AE838EF%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Do%20the%20same%20for%20other%20custom%20domain%20name%2C%20since%20I%20have%20two%20I%20have%20created%20two%20HTTP%20settings%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101217iF7AF2D5BE79CE253%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20As%20you%20can%20see%20I%20have%20now%20total%203%20HTTP%20settings%2C%20two%20I%20have%20created%20just%20now%20and%20the%20third%20default%20one%20which%20we%20will%20delete%20soon%2C%20notice%20there%20is%20no%20custom%20probe%20as%20of%20now%2C%20we%20are%20going%20to%20add%20one%20using%20PowerShell%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101218iE91E74665D7F9B01%22%20%2F%3E%20%3CBR%20%2F%3E%20Add%20Multi%20Site%20Listener%20for%20customer%20domain%20%3CBR%20%2F%3E%20Create%20two%20Multi%20Site%20Listeners%2C%20one%20for%20each%20custom%20domain%20name%2C%20if%20you%20have%20more%20custom%20domain%20name%20then%20you%20can%20create%20Multi%20Site%20Listeners%20based%20on%20the%20number%20of%20domains%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20On%20the%20Application%20Gateway%20with%20WAF%20Enabled%2C%20click%20on%20%3CB%3E%20Listeners%20%3C%2FB%3E%20then%20click%20on%20%3CB%3E%20Multi-Site%20%3C%2FB%3E%20%2C%20we%20will%20delete%20the%20default%20one%20once%20all%20dependencies%20are%20deleted.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101219iF4E68CA039E2E813%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20On%20the%20Add%2C%20name%20the%20listener%2C%20under%20%3CB%3E%20Host%20name%20%3C%2FB%3E%20make%20sure%20to%20add%20the%20domain%20name%2C%20do%20the%20same%20for%20other%20custom%20domain%20names%2C%20since%20we%20did%20not%20add%20or%20change%20anything%20on%20Frontend%20IP%20Configuration%20or%20Frontend%20port%20we%20will%20not%20select%20anything%20else.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101220i572608AA748B91DF%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101221iAABABEA9F97E8BEA%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20You%20will%20see%20three%20listeners%2C%20two%20we%20have%20created%20just%20now%20and%20third%20is%20the%20default%20one.%20We%20will%20delete%20default%20one%20soon.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101222i670414B86F04F2C4%22%20%2F%3E%20%3CBR%20%2F%3E%20Create%20Rule%20%3CBR%20%2F%3E%20Create%20two%20Rules%2C%20one%20for%20each%20custom%20domain%20name%2C%20if%20you%20have%20more%20custom%20domain%20name%20then%20you%20can%20create%20Rules%20based%20on%20the%20number%20of%20domains%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20On%20the%20Application%20Gateway%20with%20WAF%20Enabled%2C%20click%20on%20%3CB%3E%20Rules%20%3C%2FB%3E%20then%20click%20on%20%3CB%3E%20Basic%20%3C%2FB%3E%20%2C%20we%20will%20delete%20the%20default%20one%20once%20all%20dependencies%20are%20deleted.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101223i0493C9998A0EAC4C%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20On%20the%20%3CB%3E%20Add%20%3C%2FB%3E%20%3CB%3E%20Basic%20%3C%2FB%3E%20%3CB%3E%20Rule%20%3C%2FB%3E%20%2C%20name%20the%20rule%20and%20select%20the%20required%20listener%20and%20HTTP%20Settings%2C%20we%20have%20created%20two%20listeners%20and%20two%20http%20settings%20for%20each%20custom%20domain%2C%20associate%20the%20rule%20with%20its%20own%20custom%20domain%20%3CB%3E%20Listener%20%3C%2FB%3E%20and%20%3CB%3E%20HTTP%20Setting%20%3C%2FB%3E%20.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101224i2E66DF4C57ED4808%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Create%20another%20one%20for%20pk.salah.com%20listener%20and%20HTTP%20Setting%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101225i4F396B644872F839%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Notice%20we%20have%20three%20rules%20including%20default%20one%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101226i07D8D31C7392036F%22%20%2F%3E%20%3CBR%20%2F%3E%20Delete%20Default%20Listener%2C%20HTTP%20Setting%20and%20Rule%20%3CBR%20%2F%3E%20First%20let%20us%20delete%20the%20default%20rule%2C%20click%20on%20%3CB%3E%20Rules%2C%20%3C%2FB%3E%20select%20the%20default%20rule%20named%20%3CB%3E%20rule1%20%3C%2FB%3E%20and%20then%20click%20on%20%3CB%3E%20Delete%20%3C%2FB%3E%20and%20click%20%3CB%3E%20Yes%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101227i4FBBF4964B58FA64%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101228i4C37A906295AD7FA%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Next%2C%20we%20will%20Delete%20Default%20Listener%2C%20click%20on%20Listeners%2C%20then%20click%20on%20default%20Listener%20named%20appGatewayHttpListener%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101229iBB5F74B914B9BE95%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Click%20on%20%3CB%3E%20Delete%20%3C%2FB%3E%20then%20%3CB%3E%20yes%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101230iCF9E4FCD99EAAD51%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20You%20will%20be%20asked%20for%20the%20confirmation%20to%20update%20the%20resources%20click%20ok%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101231i40AE9001797EBA72%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Next%2C%20we%20will%20delete%20default%20http%20settings%2C%20click%20on%20HTTP%20Settings%2C%20then%20click%20on%20default%20HTTP%20Settings%20named%20%3CB%3E%20appGatewayBackendHttpSettings%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101232iD95FB9AA02525374%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Click%20on%20%3CB%3E%20Delete%20%3C%2FB%3E%20and%20then%20%3CB%3E%20Yes%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101233iB40AB0C59222D685%22%20%2F%3E%20%3CB%3E%20%3C%2FB%3E%20%3CBR%20%2F%3E%20Run%20the%20PowerShell%20Commands%20for%20application%20gateway%20%3CBR%20%2F%3E%20By%20running%20the%20PowerShell%20commands%2C%20we%20are%20configuring%20application%20gateway%20with%20custom%20Probes%2C%20there%20will%20be%20two%20probes%20for%20each%20HTTP%20Settings%2C%20configuring%20HTTP%20settings%20to%20accept%20the%20custom%20domain%20names%2C%20configuring%20custom%20probe%20to%20be%20compatible%20and%20work%20with%20App%20Service%20by%20using%20%3CB%3E%20%E2%80%9C-PickHostNameFromBackendHttpSettings%E2%80%9D%20%3C%2FB%3E%20which%20is%20required%20by%20probe%20to%20make%20work%20with%20App%20Service.%20In%20the%20typical%20guide%20for%20setting%20up%20an%20App%20Service%20behind%20an%20existing%20Application%20Gateway%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapplication-gateway%2Fapplication-gateway-web-app-powershell%23configure-a-web-app-behind-an-existing-application-gateway%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3E%20https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapplication-gateway%2Fapplication-gateway-web-app-powershell%23configure-a-web-app-behind-an-existing-application-gateway%20%3C%2FA%3E%20which%20uses%20%3CB%3E%20%E2%80%9C-PickHostNameFromBackendAddress%E2%80%9D%20%3C%2FB%3E%20with%20HTTP%20Settings%2C%20which%20would%20use%20the%20*.azurewebsites.net%20hostname%20when%20connecting%20to%20the%20backend%20App%20Service.%20When%20that%20configuration%20is%20in%20place%2C%20authentication%20goes%20towards%20the%20*.azurewebsites.net%20hostname%20instead%20of%20the%20custom%20domain%2C%20Since%20we%20have%20multiple%20custom%20domain%20names%20instead%20of%20using%20%3CB%3E%20%E2%80%9C-PickHostNameFromBackendAddress%E2%80%9D%20%3C%2FB%3E%20we%20will%20use%20%3CB%3E%20%E2%80%9C-HostName%E2%80%9D%20%3C%2FB%3E%20in%20each%20HTTP%20Settings%2C%20in%20our%20example%20we%20will%20use%20%3CB%3E%20-HostName%20%E2%80%9Ckw.salah.co%E2%80%9D%20%3C%2FB%3E%20with%20kw%20http%20settings%2C%20and%20%3CB%3E%20-HostName%20%E2%80%9Cpk.salah.co%E2%80%9D%20%3C%2FB%3E%20with%20pk%20http%20settings%2C%20that%20is%20the%20reason%20we%20have%20created%20multiple%20http%20settings%2C%20rules%2C%20listeners%20and%20Custom%20Probes.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20In%20the%20following%20script%20change%20the%20Resource%20Group%20name%2C%20application%20gateway%20name%2C%20custom%20domain%20name%2C%20probe%20name%20etc.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%23%20Retrieve%20existing%20resource%20group%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%24rg%20%3D%20Get-AzureRmResourceGroup%20-Name%20%22testappgwrg%22%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%23%20Retrieve%20an%20existing%20application%20gateway%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%24gw%20%3D%20Get-AzureRmApplicationGateway%20-Name%20testappgw%20-ResourceGroupName%20%24rg.ResourceGroupName%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%23%20Define%20the%20status%20codes%20to%20match%20for%20the%20probe%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%24match%3DNew-AzureRmApplicationGatewayProbeHealthResponseMatch%20-StatusCode%20200-399%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%23%20Add%20a%20new%20probe%20to%20the%20application%20gateway%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20Add-AzureRmApplicationGatewayProbeConfig%20-name%20webappprobe2%20-ApplicationGateway%20%24gw%20-Protocol%20Http%20-Path%20%2F%20-Interval%2030%20-Timeout%20120%20-UnhealthyThreshold%203%20-PickHostNameFromBackendHttpSettings%20-Match%20%24match%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%23%20Add%20a%20new%20probe%20to%20the%20application%20gateway%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20Add-AzureRmApplicationGatewayProbeConfig%20-name%20webappprobe3%20-ApplicationGateway%20%24gw%20-Protocol%20Http%20-Path%20%2F%20-Interval%2030%20-Timeout%20120%20-UnhealthyThreshold%203%20-PickHostNameFromBackendHttpSettings%20-Match%20%24match%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%23%20Retrieve%20the%20newly%20added%20probe%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%24probe%20%3D%20Get-AzureRmApplicationGatewayProbeConfig%20-name%20webappprobe2%20-ApplicationGateway%20%24gw%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%23%20Retrieve%20the%20newly%20added%20probe%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%24probe1%20%3D%20Get-AzureRmApplicationGatewayProbeConfig%20-name%20webappprobe3%20-ApplicationGateway%20%24gw%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%23%20Configure%20an%20existing%20backend%20http%20setting%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20Set-AzureRmApplicationGatewayBackendHttpSettings%20-Name%20kwhttpsettings%20-ApplicationGateway%20%24gw%20-HostName%20%22kw.salah.co%22%20-Port%2080%20-Protocol%20http%20-CookieBasedAffinity%20Disabled%20-RequestTimeout%2030%20-Probe%20%24probe%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%23%20Configure%20an%20existing%20backend%20http%20setting%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20Set-AzureRmApplicationGatewayBackendHttpSettings%20-Name%20pkhttpsettings%20-ApplicationGateway%20%24gw%20-HostName%20%22pk.salah.co%22%20-Port%2080%20-Protocol%20http%20-CookieBasedAffinity%20Disabled%20-RequestTimeout%2030%20-Probe%20%24probe1%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20%23%20Update%20the%20application%20gateway%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CB%3E%20Set-AzureRmApplicationGateway%20-ApplicationGateway%20%24gw%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Once%20the%20Script%20is%20done%2C%20it%20would%20update%20the%20application%20gateway%20and%20update%20the%20settings%2C%20I%20am%20just%20going%20to%20share%20the%20screen%20shot%20of%20the%20settings%20to%20notice%20the%20changes%20in%20HTTP%20Settings%20and%20Probes%20which%20were%20not%20there%20while%20creating%20those.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101234iD9913FC642D37FD7%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101235i541B74804F37BC3E%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20In%20case%20you%20want%20to%20verify%20Health%20Probe%20Settings%2C%20notive%20Host%20is%20empty%20this%20is%20because%20we%20have%20used%20%3CB%3E%20%E2%80%9C-PickHostNameFromBackendHttpSettings%E2%80%9D%20%3C%2FB%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101236iF36459366D5E6D9A%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Since%20we%20have%20created%20and%20configured%20Application%20gateway%2C%20it%20is%20time%20now%20to%20create%20CNAME%20record%20for%20each%20custom%20domain%20from%20External%20DNS.%20%3CBR%20%2F%3E%20Create%20CNAME%20record%20for%20each%20domain%20%3CBR%20%2F%3E%20During%20creation%20of%20application%20gateway%2C%20we%20have%20provided%20DNS%20name%20for%20the%20public%20IP%20address%20of%20application%20gateway%2C%20we%20are%20going%20to%20create%20two%20CNAME%20record%20in%20external%20DNS%20pointing%20to%20the%20DNS%20name%20of%20application%20gateway%20Public%20IP%20Address.%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101237i55ED8B8FF9343422%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101238iD0E45299BB1780D9%22%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20It%20would%20take%20time%20to%20update%20the%20DNS%20you%20can%20verify%20DNS%20updated%20or%20not%20by%20doing%20nslookup%20from%20your%20own%20device%2C%20mine%20is%20updated%20after%205%20minutes.%20As%20soon%20as%20DNS%20is%20updated%20when%20I%20browse%20kw.salah.co%20it%20is%20connecting%20me%20to%20the%20site%20contents%20related%20to%20kw%20and%20when%20I%20browse%20pk.salah.co%20it%20is%20connecting%20me%20to%20different%20contents%20related%20pk.%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-392639%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Jul%2018%2C%202018%20This%20post%20was%20contributed%20by%20Salahuddin%20Khatri.%3C%2FLINGO-TEASER%3E
Microsoft
First published on MSDN on Jul 18, 2018
This post was contributed by Salahuddin Khatri.

Setting up Application Gateway with WAF with an App Service that uses multiple Custom Domain names


I came across in a scenario in which customer is using WordPress Multisite configuration on Azure App Service with Linux (Multitenant) and publishing Azure App Service using Application Gateway to utilize WAF functionality.

Just so you know the template available in Azure Market Place for WordPress with App Service on Linux is deployed on a Linux container and you cannot enable Multisite feature in it unless you modify the container and then deploy the whole container, I have decided to deploy the App Service on Linux and then installed WordPress in it and then enabled Multi Site feature. For Those who doesn’t know the Multi site feature of WordPress, A multisite network is a collection of sites that all share the same WordPress installation. They can also share plugins and themes. The individual sites in the network are virtual sites in the sense that they do not have their own directories on your server, although they do have separate directories for media uploads within the shared installation, and they do have separate tables in the database for more information please review here https://codex.wordpress.org/Create_A_Network .

Just to let you know what are we going to do in this article, we will go through step by step where we are going to use Azure App Service (Multitenant) with multiple custom domain names and we are going to publish Azure App Service using Application Gateway with WAF, where application gateway will accept multiple custom domain names and will forward the request to one back end which is Azure App Service (Multitenant), I will not go through installing App Service and installing WordPress along with Multisite configuration, as this is a unique scenario I thought to write a blog post about it.
Prerequisites
As a prerequisite there is nothing much, but it would be assumed that App Service is deployed and configured, application gateway is deployed but not configured because we are going to do that together and access to External DNS
Before We Start!!
Before we start, since I have two websites which I want to access using Application Gateway, in this blog I am going to use my own custom domain name salah.co whereas kw.salah.co and pk.salah.co will be subdomain names added and verified in Azure App Service using awverify and CNAME record will be pointing to Application gateway IP Address domain name.

Ok enough about scenario and let us get it going further with real work
Adding Custom Domain in Web Apps
We are going to need to prepare the App Service to accept requests on the custom domain that routes through the Application Gateway. For this, we need to first add the custom domain on the App Service. You can follow the regular guide to configure a custom domain by using awverify records to avoid adjusting the domain’s actual records ( https://docs.microsoft.com/en-us/azure/app-service/app-service-custom-domain-name-migrate ), since our purpose is to add custom domain name in Azure and for that we have to use awverify record in external DNS pointing to App Service URL so that App Service will allow us to add those custom domain names. Go to your external DNS and based on your domain names create the txt records pointing to App Service URL, below is what I have done in my External DNS



Let us open App Service and go to Custom Domain option and click on Add hostname to add the required domains



On the Add hostname under hostname write down the required domain pk.salah.co and click Validate



As the awverify txt record is already created, Azure App Service has verified domain ownership and hostname availability, click on Add hostname to add the domain name in Azure App Service, do the same for your other domains



I have added both domains in Azure App Service


Setting up the Application Gateway
Now we have added custom domains in Azure App Service, let us configure application gateway with WAF to accept custom multiple domain names and send it to Azure App Service, I have also done other configuration in Azure App Service with WordPress and Multisite configuration to Map the domains etc.

We are going to use the mixture of PowerShell and GUI for this, as some required settings we need to set are only available in PowerShell for now.

The typical guide for setting up an App Service behind an existing Application Gateway is here: https://docs.microsoft.com/en-us/azure/application-gateway/application-gateway-web-app-powershel... , however this guide will help you to configure the application gateway with default configuration to connect with Azure App Service, where App service is configured with one custom domain name or no custom domain name at all, as well as same guide can create application gateway if does not exist and the connect with Azure App service, where App service is configured with one custom domain name or no custom domain name at all.

Our scenario is different, we have multiple custom domain names and we want Application Gateway to accept and connect to Azure App Service with multiple domain names where I have configured Multi Site with WordPress.

Here is What are we going to do,

1. We will create an application gateway with WAF

2. We will configure default Backend pool to connect to App Service

3. We will create two new http Settings with custom probe one for each domain, if you have more than one domain then you must create Http Settings based on number of custom domains

4. We will create two multi-site listeners one for each domain, if you have more then one domain then you must create listeners based on number of custom domains

5. We will create two Rules one for each Listener

6. We will delete default Application Gateway settings

7. We will run commands from PowerShell to create custom Probe with required settings to make it work for App service

8. We will configure Http settings to accept and work for custom domains





Create Application Gateway
Input the application gateway name, location and RG on the basic information blade, I am naming my application gateway as testappgw



I am going to select a VNET with dedicated subnet for application gateway, select the Public IP under IP Address type and then select create new Public IP Address, define the name for the DNS name of the Public IP Address, this is necessary because we are going to use this name for CNAME creation with your own DNS, configure Listener with port 80 since in this example I am going to have HTTP website, select other required options and click OK review the settings and then click ok



Since the application gateway is created, we will now start creating HTTP Settings, Multisite Listener etc as mentioned before
Editing existing / default Backend pool to connect App Service
On the Application Gateway with WAF Enabled, click on Backend Pools then open the default appGatewayBackendPool



under name type the name of Azure Web App in our scenario it is sitewordpressss.azurewebsites.net then save


Add new HTTP Settings
Create two HTTP Settings, one for each custom domain name, if you have more custom domain name then you can create HTTP settings based on the number of domains

On the Application Gateway with WAF Enabled, click on HTTP Settings then click on Add , we will delete the default one once all dependencies are deleted.



On the Add HTTP Settings, fill the fields, as per my scenario I do not need other settings to be enabled, changed Request timeout to 30 as per requirements.



Do the same for other custom domain name, since I have two I have created two HTTP settings



As you can see I have now total 3 HTTP settings, two I have created just now and the third default one which we will delete soon, notice there is no custom probe as of now, we are going to add one using PowerShell


Add Multi Site Listener for customer domain
Create two Multi Site Listeners, one for each custom domain name, if you have more custom domain name then you can create Multi Site Listeners based on the number of domains

On the Application Gateway with WAF Enabled, click on Listeners then click on Multi-Site , we will delete the default one once all dependencies are deleted.



On the Add, name the listener, under Host name make sure to add the domain name, do the same for other custom domain names, since we did not add or change anything on Frontend IP Configuration or Frontend port we will not select anything else.





You will see three listeners, two we have created just now and third is the default one. We will delete default one soon.


Create Rule
Create two Rules, one for each custom domain name, if you have more custom domain name then you can create Rules based on the number of domains

On the Application Gateway with WAF Enabled, click on Rules then click on Basic , we will delete the default one once all dependencies are deleted.



On the Add Basic Rule , name the rule and select the required listener and HTTP Settings, we have created two listeners and two http settings for each custom domain, associate the rule with its own custom domain Listener and HTTP Setting .



Create another one for pk.salah.com listener and HTTP Setting



Notice we have three rules including default one


Delete Default Listener, HTTP Setting and Rule
First let us delete the default rule, click on Rules, select the default rule named rule1 and then click on Delete and click Yes





Next, we will Delete Default Listener, click on Listeners, then click on default Listener named appGatewayHttpListener



Click on Delete then yes



You will be asked for the confirmation to update the resources click ok



Next, we will delete default http settings, click on HTTP Settings, then click on default HTTP Settings named appGatewayBackendHttpSettings



Click on Delete and then Yes


Run the PowerShell Commands for application gateway
By running the PowerShell commands, we are configuring application gateway with custom Probes, there will be two probes for each HTTP Settings, configuring HTTP settings to accept the custom domain names, configuring custom probe to be compatible and work with App Service by using “-PickHostNameFromBackendHttpSettings” which is required by probe to make work with App Service. In the typical guide for setting up an App Service behind an existing Application Gateway https://docs.microsoft.com/en-us/azure/application-gateway/application-gateway-web-app-powershel... which uses “-PickHostNameFromBackendAddress” with HTTP Settings, which would use the *.azurewebsites.net hostname when connecting to the backend App Service. When that configuration is in place, authentication goes towards the *.azurewebsites.net hostname instead of the custom domain, Since we have multiple custom domain names instead of using “-PickHostNameFromBackendAddress” we will use “-HostName” in each HTTP Settings, in our example we will use -HostName “kw.salah.co” with kw http settings, and -HostName “pk.salah.co” with pk http settings, that is the reason we have created multiple http settings, rules, listeners and Custom Probes.

In the following script change the Resource Group name, application gateway name, custom domain name, probe name etc.

# Retrieve existing resource group

$rg = Get-AzureRmResourceGroup -Name "testappgwrg"

# Retrieve an existing application gateway

$gw = Get-AzureRmApplicationGateway -Name testappgw -ResourceGroupName $rg.ResourceGroupName

# Define the status codes to match for the probe

$match=New-AzureRmApplicationGatewayProbeHealthResponseMatch -StatusCode 200-399

# Add a new probe to the application gateway

Add-AzureRmApplicationGatewayProbeConfig -name webappprobe2 -ApplicationGateway $gw -Protocol Http -Path / -Interval 30 -Timeout 120 -UnhealthyThreshold 3 -PickHostNameFromBackendHttpSettings -Match $match

# Add a new probe to the application gateway

Add-AzureRmApplicationGatewayProbeConfig -name webappprobe3 -ApplicationGateway $gw -Protocol Http -Path / -Interval 30 -Timeout 120 -UnhealthyThreshold 3 -PickHostNameFromBackendHttpSettings -Match $match

# Retrieve the newly added probe

$probe = Get-AzureRmApplicationGatewayProbeConfig -name webappprobe2 -ApplicationGateway $gw

# Retrieve the newly added probe

$probe1 = Get-AzureRmApplicationGatewayProbeConfig -name webappprobe3 -ApplicationGateway $gw

# Configure an existing backend http setting

Set-AzureRmApplicationGatewayBackendHttpSettings -Name kwhttpsettings -ApplicationGateway $gw -HostName "kw.salah.co" -Port 80 -Protocol http -CookieBasedAffinity Disabled -RequestTimeout 30 -Probe $probe

# Configure an existing backend http setting

Set-AzureRmApplicationGatewayBackendHttpSettings -Name pkhttpsettings -ApplicationGateway $gw -HostName "pk.salah.co" -Port 80 -Protocol http -CookieBasedAffinity Disabled -RequestTimeout 30 -Probe $probe1

# Update the application gateway

Set-AzureRmApplicationGateway -ApplicationGateway $gw

Once the Script is done, it would update the application gateway and update the settings, I am just going to share the screen shot of the settings to notice the changes in HTTP Settings and Probes which were not there while creating those.





In case you want to verify Health Probe Settings, notive Host is empty this is because we have used “-PickHostNameFromBackendHttpSettings”



Since we have created and configured Application gateway, it is time now to create CNAME record for each custom domain from External DNS.
Create CNAME record for each domain
During creation of application gateway, we have provided DNS name for the public IP address of application gateway, we are going to create two CNAME record in external DNS pointing to the DNS name of application gateway Public IP Address.





It would take time to update the DNS you can verify DNS updated or not by doing nslookup from your own device, mine is updated after 5 minutes. As soon as DNS is updated when I browse kw.salah.co it is connecting me to the site contents related to kw and when I browse pk.salah.co it is connecting me to different contents related pk.