Troubleshoot HTTPS 502 error when Application Gateway in front of API management self-hosted gateway

Published Jun 09 2021 04:55 PM 1,336 Views
Microsoft

We will go through the below topics in the blog:

  1. Introduction on APIM self-hosted gateway and how do we configure custom domain for it.
  2. Case Study: 502 error returned by V1 Application gateway when using HTTPS protocol.
  3. V2 Application gateway’s difference between V1 when verify server cert.

 

*In this blog, AG = Application Gateway. SH-gateway = self-hosted gateway.

 

If you are not familiar with AG and APIM integration, here are two well composed blogs that let us know how to work with AGv1, AGv2 and Managed APIM.

 

APIM with Application Gateway v1 - Microsoft Tech Community

Integrating API Management with App Gateway V2 - Microsoft Tech Community

 

Introduction on APIM self-hosted gateway and how do we configure custom domain for it.

 

To describe in brief, self-hosted gateway is APIM packaged in a Linux Docker image and can be deploy to any VM or on-prem machines.

More information here: Self-hosted gateway overview | Microsoft Docs

The blog will not include deploying the self-hosted gateway as the thesis is to explain some common issues that we will get when an App gateway is in front of it.

One easy way to find out if your self-hosted gateway is pulling API configurations from Azure is to check this ‘Status’.

 

Yixuan_Wang_0-1623209739153.png

 

A green light means the heartbeat connectivity is successfully established.

Configure the custom domain here at the ‘Hostname’ blade.

 

Yixuan_Wang_1-1623209739174.png

 

We will need to upload the pfx format first to the ‘Certificate’ blade of the APIM. So we can list it out here.

 

Yixuan_Wang_2-1623209739199.png

 

Yixuan_Wang_3-1623209739211.png

 

 

Once we made the hostname change, if we are following the docker container log for the self-hosted gateway, we can see an event being created. That means the hostname has taken effect.

 

Yixuan_Wang_4-1623209739233.png

 

Case Study: 502 errors returned by V1 Application gateway when using HTTPS

 

Background:

 

My V1 AG’s backend setting is targeting my SH-gateway’s hosting VM’s public IP.

Yixuan_Wang_5-1623209739237.png

 

I used a self-signed certificate for my SH-gateway’s domain. And have uploaded the cer format of this certificate to the AG.

 

Yixuan_Wang_6-1623209739239.png

 

Yixuan_Wang_7-1623209739241.png

 

 

I have over-written the hostname in http setting and custom probe.

 

Yixuan_Wang_8-1623209739248.png

 

 

Yixuan_Wang_9-1623209739258.png

 

 

Test HTTPS with postman, got 502 error.

 

Yixuan_Wang_10-1623209739279.png

 

 

HTTP however is working as expected, so I am suspecting the issue could be with the certificate. However, I have already uploaded the cer format to AG.

Yixuan_Wang_11-1623209739288.png

 

 

To narrow down and test HTTPS connectivity, I bypassed the AG and accessed the SH-gateway directly with IP:port. The IP is the docker container hosting VM’s public IP.

openssl s_client -connect XX.XX.XX.XX:443 -showcerts

 

Yixuan_Wang_12-1623209739309.png

 

 

As in the screenshot, the certificate that the server returned is not the custom domain certificate I configured for the SH-gateway. It is returning test.apim.net, the default self-signed cert.

I realized that when we access the APIM with IP, there is no SNI header in the request. Based on the APIM documentation:

 

Yixuan_Wang_13-1623209739321.png

 

 

In other words, for Managed APIM, we need to choose a default custom certificate for APIM to return, and the catch here is that SH-gateway will not let us choose defaultSslBinding. So, if there is no SNI header in the requests, SH-gateway always return the default test.apim.net cert.

 

But I was expecting the AG overwrites the hostname header and the SNI supposed to be set. After some research, I found the answer in AG’s documentation.

 

Yixuan_Wang_14-1623209739337.png

 

In conclusion, V1 AG set requests’ SNI uses backend pool setting, which means the hostname overwrites does not modify the SNI header, hence if we put IP as a backend pool target, SH-gateway’s server cert always mismatches with the cert we uploaded to the AG.

 

There are two solution options for this issue with AGv1:

  • Use FQDN as a backend target. Don’t use IP.
  • Use IP as a backend target, and download the test.apim.net cert, upload it to AG’s http setting. We need to give up custom domain with this solution.

 

For the solution No.2, I navigated to SH-gateway by IP with browser and downloaded the certificate from the browser.

 

Yixuan_Wang_17-1623209963825.png

 

V2 AG’s difference when verify server certificate

 

Since the AG will verify server cert’s root cert, and the test.apim.net does not have a root cert. The HTTPS requests will get 502 even if we uploaded this cert to APIM.

Yixuan_Wang_16-1623209739346.png

 

Therefore, if we configure custom domain for SH-gateway and use V2 AG in front of it,

1)The custom domain cert needs to be issued with well-known CA

2)Or it can be self-signed with a root cert, with the root cert uploaded to AG.

 

Hope this blog will help you identify the reason we get 502 when configure AG with APIM SH-gateway.

 

Appendix:

 

Enabling end to end TLS on Azure Application Gateway | Microsoft Docs

What is SNI? How TLS server name indication works | Cloudflare

1 Comment
%3CLINGO-SUB%20id%3D%22lingo-sub-2429353%22%20slang%3D%22en-US%22%3ETroubleshoot%20HTTPS%20502%20error%20when%20Application%20Gateway%20in%20front%20of%20API%20management%20self-hosted%20gateway%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2429353%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20will%20go%20through%20the%20below%20topics%20in%20the%20blog%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EIntroduction%20on%20APIM%20self-hosted%20gateway%20and%20how%20do%20we%20configure%20custom%20domain%20for%20it.%3C%2FLI%3E%0A%3CLI%3ECase%20Study%3A%20502%20error%20returned%20by%20%3CSTRONG%3EV1%3C%2FSTRONG%3E%20Application%20gateway%20when%20using%20HTTPS%20protocol.%3C%2FLI%3E%0A%3CLI%3EV2%20Application%20gateway%E2%80%99s%20difference%20between%20V1%20when%20verify%20server%20cert.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CEM%3E*In%20this%20blog%2C%20AG%20%3D%20Application%20Gateway.%20SH-gateway%20%3D%20self-hosted%20gateway.%3C%2FEM%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20you%20are%20not%20familiar%20with%20AG%20and%20APIM%20integration%2C%20here%20are%20two%20well%20composed%20blogs%20that%20let%20us%20know%20how%20to%20work%20with%20AGv1%2C%20AGv2%20and%20%3CSTRONG%3EManaged%20APIM%3C%2FSTRONG%3E.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-paas-blog%2Fapim-with-application-gateway-v1%2Fba-p%2F1795180%22%20target%3D%22_blank%22%3EAPIM%20with%20Application%20Gateway%20v1%20-%20Microsoft%20Tech%20Community%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fazure-paas-blog%2Fintegrating-api-management-with-app-gateway-v2%2Fba-p%2F1241650%22%20target%3D%22_blank%22%3EIntegrating%20API%20Management%20with%20App%20Gateway%20V2%20-%20Microsoft%20Tech%20Community%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CSTRONG%3EIntroduction%20on%20APIM%20self-hosted%20gateway%20and%20how%20do%20we%20configure%20custom%20domain%20for%20it.%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20describe%20in%20brief%2C%20self-hosted%20gateway%20is%20APIM%20packaged%20in%20a%20Linux%20Docker%20image%20and%20can%20be%20deploy%20to%20any%20VM%20or%20on-prem%20machines.%3C%2FP%3E%0A%3CP%3EMore%20information%20here%3A%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapi-management%2Fself-hosted-gateway-overview%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3ESelf-hosted%20gateway%20overview%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3EThe%20blog%20will%20not%20include%20deploying%20the%20self-hosted%20gateway%20as%20the%20thesis%20is%20to%20explain%20some%20common%20issues%20that%20we%20will%20get%20when%20an%20App%20gateway%20is%20in%20front%20of%20it.%3C%2FP%3E%0A%3CP%3EOne%20easy%20way%20to%20find%20out%20if%20your%20self-hosted%20gateway%20is%20pulling%20API%20configurations%20from%20Azure%20is%20to%20check%20this%20%E2%80%98Status%E2%80%99.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_0-1623209739153.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287341i84128F543BDD5351%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_0-1623209739153.png%22%20alt%3D%22Yixuan_Wang_0-1623209739153.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EA%20green%20light%20means%20the%20heartbeat%20connectivity%20is%20successfully%20established.%3C%2FP%3E%0A%3CP%3EConfigure%20the%20custom%20domain%20here%20at%20the%20%E2%80%98Hostname%E2%80%99%20blade.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_1-1623209739174.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287340iD97206A0DDDBD1EA%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_1-1623209739174.png%22%20alt%3D%22Yixuan_Wang_1-1623209739174.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20will%20need%20to%20upload%20the%20pfx%20format%20first%20to%20the%20%E2%80%98Certificate%E2%80%99%20blade%20of%20the%20APIM.%20So%20we%20can%20list%20it%20out%20here.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_2-1623209739199.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287342iE91BB7A84E373829%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_2-1623209739199.png%22%20alt%3D%22Yixuan_Wang_2-1623209739199.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_3-1623209739211.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287344i4FC9C55107B8179E%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_3-1623209739211.png%22%20alt%3D%22Yixuan_Wang_3-1623209739211.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20we%20made%20the%20hostname%20change%2C%20if%20we%20are%20following%20the%20docker%20container%20log%20for%20the%20self-hosted%20gateway%2C%20we%20can%20see%20an%20event%20being%20created.%20That%20means%20the%20hostname%20has%20taken%20effect.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_4-1623209739233.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287345i7329FF81C05B70FE%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_4-1623209739233.png%22%20alt%3D%22Yixuan_Wang_4-1623209739233.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CSTRONG%3ECase%20Study%3A%20502%20errors%20returned%20by%20V1%20Application%20gateway%20when%20using%20HTTPS%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBackground%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMy%20V1%20AG%E2%80%99s%20backend%20setting%20is%20targeting%20my%20SH-gateway%E2%80%99s%20hosting%20VM%E2%80%99s%20public%20IP.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_5-1623209739237.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287346i08236635485B0D78%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_5-1623209739237.png%22%20alt%3D%22Yixuan_Wang_5-1623209739237.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20used%20a%20self-signed%20certificate%20for%20my%20SH-gateway%E2%80%99s%20domain.%20And%20have%20uploaded%20the%20cer%20format%20of%20this%20certificate%20to%20the%20AG.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_6-1623209739239.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287347i3DCE3DD5819FEF4E%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_6-1623209739239.png%22%20alt%3D%22Yixuan_Wang_6-1623209739239.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_7-1623209739241.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287348i153A961B09B21009%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_7-1623209739241.png%22%20alt%3D%22Yixuan_Wang_7-1623209739241.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20have%20over-written%20the%20hostname%20in%20http%20setting%20and%20custom%20probe.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_8-1623209739248.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287349i14DB9F05DDFE141A%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_8-1623209739248.png%22%20alt%3D%22Yixuan_Wang_8-1623209739248.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_9-1623209739258.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287350i316EE433C0B35F6F%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_9-1623209739258.png%22%20alt%3D%22Yixuan_Wang_9-1623209739258.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETest%20HTTPS%20with%20postman%2C%20got%20502%20error.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_10-1623209739279.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287352i32430132CA256A23%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_10-1623209739279.png%22%20alt%3D%22Yixuan_Wang_10-1623209739279.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHTTP%20however%20is%20working%20as%20expected%2C%20so%20I%20am%20suspecting%20the%20issue%20could%20be%20with%20the%20certificate.%20However%2C%20I%20have%20already%20uploaded%20the%20cer%20format%20to%20AG.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_11-1623209739288.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287351i74CF7EB1AF400190%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_11-1623209739288.png%22%20alt%3D%22Yixuan_Wang_11-1623209739288.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20narrow%20down%20and%20test%20HTTPS%20connectivity%2C%20I%20bypassed%20the%20AG%20and%20accessed%20the%20SH-gateway%20directly%20with%20IP%3Aport.%20The%20IP%20is%20the%20docker%20container%20hosting%20VM%E2%80%99s%20public%20IP.%3C%2FP%3E%0A%3CP%3Eopenssl%20s_client%20-connect%20XX.XX.XX.XX%3A443%20-showcerts%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_12-1623209739309.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287355i7A7D3E383CD11053%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_12-1623209739309.png%22%20alt%3D%22Yixuan_Wang_12-1623209739309.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20in%20the%20screenshot%2C%20the%20certificate%20that%20the%20server%20returned%20is%20not%20the%20custom%20domain%20certificate%20I%20configured%20for%20the%20SH-gateway.%20It%20is%20returning%20test.apim.net%2C%20the%20default%20self-signed%20cert.%3C%2FP%3E%0A%3CP%3EI%20realized%20that%20when%20we%20access%20the%20APIM%20with%20IP%2C%20there%20is%20no%20SNI%20header%20in%20the%20request.%20Based%20on%20the%20APIM%20documentation%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_13-1623209739321.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287354i5D920EAE3846E013%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_13-1623209739321.png%22%20alt%3D%22Yixuan_Wang_13-1623209739321.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20other%20words%2C%20for%20Managed%20APIM%2C%20we%20need%20to%20choose%20a%20default%20custom%20certificate%20for%20APIM%20to%20return%2C%20and%20%3CFONT%20color%3D%22%23FF0000%22%3E%3CSTRONG%3Ethe%20catch%20here%3C%2FSTRONG%3E%3C%2FFONT%3E%20is%20that%20SH-gateway%20will%20not%20let%20us%20choose%20defaultSslBinding.%20So%3CSTRONG%3E%2C%20if%20there%20is%20no%20SNI%20header%20in%20the%20requests%2C%20SH-gateway%20always%20return%20the%20default%20test.apim.net%20cert.%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EBut%20I%20was%20expecting%20the%20AG%20overwrites%20the%20hostname%20header%20and%20the%20SNI%20supposed%20to%20be%20set.%20After%20some%20research%2C%20I%20found%20the%20answer%20in%20AG%E2%80%99s%20documentation.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_14-1623209739337.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287353iF5175AD1E0C7656B%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_14-1623209739337.png%22%20alt%3D%22Yixuan_Wang_14-1623209739337.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20conclusion%2C%20V1%20AG%20set%20requests%E2%80%99%20SNI%20uses%20backend%20pool%20setting%2C%20which%20means%20the%20hostname%20overwrites%20does%20not%20modify%20the%20SNI%20header%2C%20hence%20if%20we%20put%20IP%20as%20a%20backend%20pool%20target%2C%20SH-gateway%E2%80%99s%20server%20cert%20always%20mismatches%20with%20the%20cert%20we%20uploaded%20to%20the%20AG.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EThere%20are%20two%20solution%20options%20for%20this%20issue%20with%20AGv1%3A%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3E%3CSTRONG%3EUse%20FQDN%20as%20a%20backend%20target.%20Don%E2%80%99t%20use%20IP.%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3CLI%3E%3CSTRONG%3EUse%20IP%20as%20a%20backend%20target%2C%20and%20download%20the%20test.apim.net%20cert%2C%20upload%20it%20to%20AG%E2%80%99s%20http%20setting.%20We%20need%20to%20give%20up%20custom%20domain%20with%20this%20solution.%3C%2FSTRONG%3E%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EFor%20the%20solution%20No.2%2C%20I%20navigated%20to%20SH-gateway%20by%20IP%20with%20browser%20and%20downloaded%20the%20certificate%20from%20the%20browser.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_17-1623209963825.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287359i2176E084912C0F86%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_17-1623209963825.png%22%20alt%3D%22Yixuan_Wang_17-1623209963825.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CFONT%20size%3D%224%22%3E%3CSTRONG%3EV2%20AG%E2%80%99s%20difference%20when%20verify%20server%20certificate%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ESince%20the%20AG%20will%20verify%20server%20cert%E2%80%99s%20root%20cert%2C%20and%20the%20test.apim.net%20does%20not%20have%20a%20root%20cert.%20The%20HTTPS%20requests%20will%20get%20502%20even%20if%20we%20uploaded%20this%20cert%20to%20APIM.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22Yixuan_Wang_16-1623209739346.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F287356i51F9100816822DA8%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22Yixuan_Wang_16-1623209739346.png%22%20alt%3D%22Yixuan_Wang_16-1623209739346.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ETherefore%2C%20if%20we%20configure%20custom%20domain%20for%20SH-gateway%20and%20use%20V2%20AG%20in%20front%20of%20it%2C%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E1)The%20custom%20domain%20cert%20needs%20to%20be%20issued%20with%20well-known%20CA%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E2)Or%20it%20can%20be%20self-signed%20with%20a%20root%20cert%2C%20with%20the%20root%20cert%20uploaded%20to%20AG.%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EHope%20this%20blog%20will%20help%20you%20identify%20the%20reason%20we%20get%20502%20when%20configure%20AG%20with%20APIM%20SH-gateway.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAppendix%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fapplication-gateway%2Fssl-overview%23tls-termination%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EEnabling%20end%20to%20end%20TLS%20on%20Azure%20Application%20Gateway%20%7C%20Microsoft%20Docs%3C%2FA%3E%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fwww.cloudflare.com%2Flearning%2Fssl%2Fwhat-is-sni%2F%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noreferrer%22%3EWhat%20is%20SNI%3F%20How%20TLS%20server%20name%20indication%20works%20%7C%20Cloudflare%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2429353%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20will%20go%20through%20the%20below%20topics%20in%20the%20blog%3A%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3EIntroduction%20on%20APIM%20self-hosted%20gateway%20and%20how%20do%20we%20configure%20custom%20domain%20for%20it.%3C%2FLI%3E%0A%3CLI%3ECase%20Study%3A%20502%20error%20returned%20by%20%3CSTRONG%3EV1%3C%2FSTRONG%3E%20Application%20gateway%20when%20using%20HTTPS%20protocol.%3C%2FLI%3E%0A%3CLI%3EV2%20Application%20gateway%E2%80%99s%20difference%20between%20V1%20when%20verify%20server%20cert.%3C%2FLI%3E%0A%3C%2FOL%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2429353%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%20API%20management%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2446556%22%20slang%3D%22en-US%22%3ERe%3A%20Troubleshoot%20HTTPS%20502%20error%20when%20Application%20Gateway%20in%20front%20of%20API%20management%20self-hosted%20gat%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2446556%22%20slang%3D%22en-US%22%3E%3CP%3EWe%20are%20planning%20to%20implement%20azure%20AGIC%20Wafv2.%20DO%20we%20have%20to%20consider%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Co-Authors
Version history
Last update:
‎Jun 08 2021 08:57 PM
Updated by: