【Azure API 管理】APIM不能连接到 App Service (APIM cannot connect to APP service)

简介: 【Azure API 管理】APIM不能连接到 App Service (APIM cannot connect to APP service)

问题描述

APIM 无法正确连接到App Service,返回500错误:

{
    "statusCode": 500,
    "message": "Internal server error",
    "activityId": "2aef4474-4067-a333-8750-3889ebad3eeb"
}

单独访问App Service,是可以成功的。当通过APIM访问时候就出现了500错误

 

问题分析

根据博文“【Azure API 管理】为调用APIM的请求启用Trace -- 调试APIM Policy的利器” 中的内容,启用APIM Trace后,在 Backend 发现真实的错误消息为:

error message :The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

这个错误信息指示,后端服务适用的证书问题。当APIM的后端服务所配置的证书为自签名证书,而不是根CA证书时,通常就会遇见此错误。 APIM服务部署在Windows操作系统所运行的PaaS VM托管上的Azure服务中。因此每个APIM实例都信任所有Windows 系统默认的根证书颁发机构。这个问题的解决办法为:

1:添加一个由受信任的CA机构颁发证书到App Service上。

2:禁止APIM与后端App Service之间的证书链验证。使用 New-AzApiManagementBackend 或 Set-AzApiManagementBackend 对APIM中所配置的后端服务 设置-SkipCertificateChainValidation  为True。

示例命令为:

$context = New-AzApiManagementContext -resourcegroup 'ContosoResourceGroup' -servicename 'ContosoAPIMService'
New-AzApiManagementBackend -Context  $context -Url 'https://contoso.com/myapi' -Protocol http -SkipCertificateChainValidation $true

参考文档

Set-AzApiManagementBackend :https://docs.microsoft.com/en-us/powershell/module/az.apimanagement/set-azapimanagementbackend?view=azps-7.3.0&viewFallbackFrom=azps-4.8.0

New-AzApiManagementBackend :https://docs.microsoft.com/en-us/powershell/module/az.apimanagement/new-azapimanagementbackend?view=azps-7.3.0&viewFallbackFrom=azps-4.8.0

 

Troubleshooting 4xx and 5xx Errors with Azure APIM serviceshttps://techcommunity.microsoft.com/t5/azure-paas-blog/troubleshooting-4xx-and-5xx-errors-with-azure-apim-services/ba-p/2115744

Scenario 7: The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel

 

Symptom:

API requests fail with Backend Connection Failure with the below error message highlighted under the errorMessage column in the diagnostic logs:

“The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel”

 

Cause:

This error is normally encountered when the backend has been configured to use a self-signed certificate instead of using a publicly trusted root CA certificate.

 

APIM services are hosted in the Azure infrastructure using PaaS VMs that run on Windows OS.

Hence, every APIM instance trusts the same default Root Certificate Authorities that all windows machines trust.

 

The list of trusted Root CAs can be downloaded using the Microsoft Trusted Root Certificate Program Participants list - https://docs.microsoft.com/en-us/security/trusted-root/participants-list

 

Resolution:

There are 2 possible solutions for resolving this issue:

  • Add a valid trusted root CA certificate that resolves to a Microsoft Trusted Root Participant list.
  • Disable certificate chain validation in order for APIM to communicate with the backend system. To configure this, you can use the New-AzApiManagementBackend (for new back end) or Set-AzApiManagementBackend (for existing back end) PowerShell cmdlets and set the -SkipCertificateChainValidation parameter to True.
相关文章
|
4月前
|
API 网络安全 网络架构
【Azure APIM】解答REST API实现"禁用自签名证书的证书链验证"中的backends参数值从那里取值的问题?
本文介绍APIM服务调用后端API时因自签名证书导致500错误的解决方案。通过REST API禁用证书链验证,关键在于获取正确的backendId(即APIM中配置的Backend名称),并调用PATCH接口设置validateCertificateChain为false,从而解决SSL/TLS信任问题。
204 6
|
4月前
|
Java 应用服务中间件 API
【App Service】部署War包到Azure云上遇404错误
Java应用部署至Azure App Service for Windows后报404,本地运行正常。经排查,日志提示类文件版本不兼容:应用由Java 17(class file version 61.0)编译,但环境仅支持到Java 11(55.0)。错误根源为Java版本不匹配。调整App Service的Java版本至17后问题解决,成功访问接口。
223 1
|
4月前
|
存储 Linux 网络安全
【Azure App Service】Root CA on App Service
Azure App Service for Windows应用连接外部SSL服务时,需确保其证书由受信任的根CA颁发。多租户环境下无法修改根证书,但ASE(单租户)可加载自定义CA证书。若遇证书信任问题,可更换为公共CA证书或将应用部署于ASE并导入私有CA证书。通过Kudu的PowerShell(Windows)或SSH(Linux)可查看当前受信任的根证书列表。
126 13
|
5月前
|
API 网络架构 容器
【Azure Container App】查看当前 Container App Environment 中的 CPU 使用情况的API
在扩展 Azure Container Apps 副本时,因 Container App Environment 的 CPU 核心数已达上限(500 cores),导致扩展失败。本文介绍如何使用 `az rest` 命令调用 Azure China Cloud 管理 API,查询当前环境的 CPU 使用情况,并提供具体操作步骤及示例。
183 16
|
5月前
|
数据安全/隐私保护
【Azure Function App】PowerShell Function 执行 Get-AzAccessToken 的返回值类型问题:System.String 与 System.Security.SecureString
将PowerShell Function部署到Azure Function App后,Get-AzAccessToken返回值类型在不同环境中有差异。正常为SecureString类型,但部分情况下为System.String类型,导致后续处理出错。解决方法是在profile.ps1中设置环境变量$env:AZUREPS_OUTPUT_PLAINTEXT_AZACCESSTOKEN=false,以禁用明文输出。
168 1
|
5月前
|
网络协议 Java Linux
【App Service】在Azure环境中如何查看App Service实例当前的网络连接情况呢?
在 Azure App Service(Windows 和 Linux)中部署应用时,分析网络连接状态是排查异常、验证端口监听及确认后端连接的关键。本文介绍如何在 Linux 环境中使用 `netstat` 命令查看特定端口(如 443、3306、6380)的连接情况,并解析输出结果。同时说明在 Windows App Service 中 `netstat` 被禁用的情况下,如何通过门户抓包等替代方法进行网络诊断。内容涵盖命令示例、操作步骤及附录说明,帮助开发者快速掌握云环境中的网络分析技巧。
156 11
|
4月前
|
缓存 监控 前端开发
顺企网 API 开发实战:搜索 / 详情接口从 0 到 1 落地(附 Elasticsearch 优化 + 错误速查)
企业API开发常陷参数、缓存、错误处理三大坑?本指南拆解顺企网双接口全流程,涵盖搜索优化、签名验证、限流应对,附可复用代码与错误速查表,助你2小时高效搞定开发,提升响应速度与稳定性。
|
4月前
|
JSON 算法 API
Python采集淘宝商品评论API接口及JSON数据返回全程指南
Python采集淘宝商品评论API接口及JSON数据返回全程指南
|
5月前
|
数据可视化 测试技术 API
从接口性能到稳定性:这些API调试工具,让你的开发过程事半功倍
在软件开发中,接口调试与测试对接口性能、稳定性、准确性及团队协作至关重要。随着开发节奏加快,传统方式已难满足需求,专业API工具成为首选。本文介绍了Apifox、Postman、YApi、SoapUI、JMeter、Swagger等主流工具,对比其功能与适用场景,并推荐Apifox作为集成度高、支持中文、可视化强的一体化解决方案,助力提升API开发与测试效率。
|
4月前
|
JSON API 数据安全/隐私保护
Python采集淘宝拍立淘按图搜索API接口及JSON数据返回全流程指南
通过以上流程,可实现淘宝拍立淘按图搜索的完整调用链路,并获取结构化的JSON商品数据,支撑电商比价、智能推荐等业务场景。