简体   繁体   English

来自Azure AppService的GET请求返回自身将返回502 Bad Gateway错误

[英]GET Request from an Azure AppService back to itself returns a 502 Bad Gateway error

I have an Azure AppService/Website that when it receives a request, part of servicing it involves making another GET request back to itself. 我有一个Azure AppService /网站,当它收到请求时,服务的一部分包括向自身发出另一个GET请求。 This is part of an HMAC workflow. 这是HMAC工作流程的一部分。 When I run it on localhost it works fine with no errors. 当我在localhost上运行它时,它运行正常,没有错误。 There is something about the Azure environment that is causing the error. 导致错误的原因与Azure环境有关。 The website is not publicly available unfortunately. 不幸的是,该网站尚未公开。

using (HttpClient httpClient = new HttpClient())
{
   ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;

   apiResponse = await httpClient.GetAsync(apiBaseAddress + "api/Survey/GetApiKey/" + appId);
   entity = await apiResponse.Content.ReadAsAsync<ClientApiRegistrationEntity>();
}

The URL being passed to GetAsync() is correct. 传递给GetAsync()的URL是正确的。 The URL has a https scheme in Azure; URL在Azure中具有https方案; locally it is just http. 在本地它只是http。 If I copy/paste the URL into a browser on my machine the request goes through. 如果我将URL复制/粘贴到计算机上的浏览器中,则请求将通过。 If I make the request on the Kudu debug console I get the 502. I have confirmed that the DNS is resolving correctly in the AppService. 如果我在Kudu调试控制台上发出请求,则得到502。我已经确认DNS在AppService中能够正确解析。 For what it is worth, the invoke-webrequest call in Kudu returns a web page with the title: "502 - Web server received an invalid response while acting as a gateway or proxy server.". 出于其价值,Kudu中的invoke-webrequest调用返回一个标题为“ 502-Web服务器在充当网关或代理服务器时收到无效响应”的网页。

Any ideas? 有任何想法吗? Suggestions? 有什么建议吗?

Just to highlight, the standard/native Azure Web Apps run in a secure environment called a sandbox. 只是要强调一下,标准/本地Azure Web Apps在称为沙箱的安全环境中运行。 Each app runs inside its own sandbox, isolating its execution from other instances on the same machine as well as providing an additional degree of security and privacy which would otherwise not be available. 每个应用程序都在其自己的沙箱中运行,从而将其执行与同一台计算机上的其他实例隔离开来,并提供其他程度的安全性和隐私性,否则这些安全性和隐私性将是不可用的。

The only way an application can be accessed via the internet is through the already-exposed HTTP (80) and HTTPS (443) TCP ports; 可以通过Internet访问应用程序的唯一方法是通过已公开的HTTP(80)和HTTPS(443)TCP端口;否则,无法访问Internet。 applications may not listen on other ports for packets arriving from the internet. 应用程序可能不会在其他端口上侦听来自Internet的数据包。 However, applications may create a socket which can listen for connections from within the sandbox. 但是,应用程序可以创建一个套接字,该套接字可以侦听来自沙箱中的连接。 For example, two processes within the same app may communicate with one another via TCP sockets; 例如,同一应用程序中的两个进程可以通过TCP套接字相互通信; connection attempts incoming from outside the sandbox, albeit they be on the same machine, will fail. 从沙箱外部传入的连接尝试(即使它们位于同一台计算机上)将失败。 Using a custom Windows container in App Service lets you make OS changes that your app needs, so it's easy to migrate on-premises app that requires custom OS and software configuration. 通过在App Service中使用自定义Windows容器,可以进行应用所需的OS更改,因此可以轻松迁移需要自定义OS和软件配置的本地应用。 See sandbox page . 请参阅沙箱页面

Based on your requirement, you may checkout these document to start-off: 根据您的要求,您可以签出这些文档以开始:

Run a custom Linux container in Azure App Service & Run a custom Windows container in Azure (Preview) 在Azure App Service中运行自定义Linux容器并在Azure中 运行自定义Windows容器(预览)

502 bad gateway errors won't be visible in the IIS logs as they're returned by the frontend servers, which forwards the requests to the worker hosting the app and there are many reasons why the frontend can return this error, but typically, 502 errors are caused by the application level issues, among them: 502错误的网关错误在前端服务器返回的IIS日志中将不可见,这会将请求转发给托管应用程序的工作程序,并且前端可以返回此错误有很多原因,但通常是502错误是由应用程序级别的问题引起的,其中包括:

• requests taking a long time •请求时间长

• application using high memory/CPU •使用高内存/ CPU的应用程序

• application crashing due to an exception •应用程序由于异常而崩溃

You may always follow the document Troubleshoot HTTP errors of "502 bad gateway" and "503 service unavailable ( https://docs.microsoft.com/en-us/azure/app-service/troubleshoot-http-502-http-503 )" in Azure App Service for identifying the issue. 您可能始终会按照文档“排除502网关错误的HTTP错误”和“ 503服务不可用”( https://docs.microsoft.com/zh-cn/azure/app-service/troubleshoot-http-502-http-503 )中的“)来识别问题。

I stumbled on this fix. 我偶然发现了此修复程序。 I was comparing application gateways between dev and prod and I noticed an inbound port rule called "DenyAllInbound" sitting on port 4096. I pulled that out and everything started working again. 我在比较开发人员和生产人员之间的应用程序网关时,发现端口4096上有一个名为“ DenyAllInbound”的入站端口规则。我将其拔出,一切又开始正常工作。 I'm not sure how that rule got there in the first place. 我不确定该规则最初是如何实现的。 It looks like a 502 is a generic "something is wrong" message from Azure. 看起来502是来自Azure的通用“某事不对劲”消息。

FWIW, I found the "DenyAllInbound" rule by using the "Connection troubleshoot" link under Monitoring for the application gateway. FWIW,我通过使用“监视应用程序网关”下的“连接疑难解答”链接找到了“ DenyAllInbound”规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Azure /映像请求502(错误网关)错误 - 间歇性 - Azure / Image request 502 (Bad gateway) error - intermittent 上传大文件 - Azure App Service 上的 502 bad gateway 错误 - Upload large file - 502 bad gateway error on Azure App Service 502 错误:使用 IronPDF 的 Azure 应用服务上的网关错误 - 502 Error: Bad Gateway on Azure App Service with IronPDF 通过SSL通过HttpWebRequest发送请求时出现错误502(错误网关) - Error 502 (Bad Gateway) when sending a request with HttpWebRequest over SSL 如何解决 502 Bad Gateway 错误 - How to troubleshoot 502 Bad Gateway error 为什么会发生“(502) Bad Gateway”错误? - Why "(502) Bad Gateway" error happen? 错误(502)错误的网关:当尝试使用WebChat通道访问Azure上部署的聊天机器人时 - Error (502) Bad Gateway: When trying to access chatbot deployed on Azure using WebChat channel 调用Web服务返回远程服务器返回错误:(502)错误的网关 - Calling web service returns The remote server returned an error: (502) Bad Gateway UCWA获得502响应(Bad Gateway,策略阻止请求被代理) - UCWA getting a 502 response (Bad Gateway, policy prevents request from being proxied) Azure CDN终结点通过502提供错误的网关 - Azure CDN endpoint giving 502 bad gateway with https
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM