【Azure APIM】解答REST API实现"禁用自签名证书的证书链验证"中的backends参数值从那里取值的问题?

问题描述

使用APIM服务时候,因为后端的API需要使用自签名证书进行验证。如果通过浏览器直接访问后端API返回正常,但是APIM请求的时候返回为500报错。

在开启Trace后,发现报错信息为:error message :The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. (参考文章:https://www.cnblogs.com/lulight/p/15961708.html)。

微软的官方给出了解决方案,只需要禁用自签名证书的证书链验证即可。但是如何关闭这个证书链的验证呢?

image

除了文章中介绍的Powershell方法外,还可以调用REST API来实现。

image

只是在REST API的URL中, backendId 这个参数从何而来呢?如何取值?

 

问题解答

根据实验,找出了这个请求中的backendId指的就是APIM门户中所配置的Backends页面中的 backend name。

 

如下图:

image

而在API配置中,则是通过 set-backend-service policy来使用这个backend。

image

 

所以,本文的问题,以上图的backend为例,在中国区APIM上,如果要禁用对这个API请求时候的自签名证书的证书链验证。

完整的URL为:

 

PATCH https://management.chinacloudapi.cn/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ApiManagement/service/{serviceName}/backends/blackbug-test-backend?api-version=2024-05-01

参数为:

{ "properties": { "description": "your custom description", "tls": { "validateCertificateChain": false, "validateCertificateName": true } } }

 

 

参考资料

 

APIM不能连接到 App Service (APIM cannot connect to APP service) : https://www.cnblogs.com/lulight/p/15961708.html 

Backend - Update : https://learn.microsoft.com/en-us/rest/api/apimanagement/backend/update?view=rest-apimanagement-2024-05-01&tabs=HTTP

禁用自签名证书的证书链验证 : https://docs.azure.cn/zh-cn/api-management/api-management-howto-mutual-certificates#disable-certificate-chain-validation-for-self-signed-certificates

Set backend service : https://learn.microsoft.com/en-us/azure/api-management/set-backend-service-policy

 
posted @ 2025-10-10 20:18  路边两盏灯  阅读(6)  评论(0)    收藏  举报