簡體   English   中英

Azure 函數應用返回 502 錯誤網關

[英]Azure function app returning 502 Bad Gateway

當我在我們的主插槽上運行 HTTP 觸發的函數應用程序時,我收到以下錯誤消息:

 Status: 502 Bad Gateway <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>502 - Web server received an invalid response while acting as a gateway or proxy server.</title> <style type="text/css"> <!-- body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;} fieldset{padding:0 15px 10px 15px;} h1{font-size:2.4em;margin:0;color:#FFF;} h2{font-size:1.7em;margin:0;color:#CC0000;} h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} #header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF; background-color:#555555;} #content{margin:0 0 0 2%;position:relative;} .content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;} --> </style> </head> <body> <div id="header"><h1>Server Error</h1></div> <div id="content"> <div class="content-container"><fieldset> <h2>502 - Web server received an invalid response while acting as a gateway or proxy server.</h2> <h3>There is a problem with the page you are looking for, and it cannot be displayed. When the Web server (while acting as a gateway or proxy) contacted the upstream content server, it received an invalid response from the content server.</h3> </fieldset></div> </div> </body> </html>

但是當我嘗試使用完全相同的代碼創建一個新的插槽和函數應用程序時,它運行良好而不會出現上述錯誤。 我們的主插槽的配置似乎有問題,但我找不到任何資源來指向它。

有沒有其他人遇到過這個問題? 你怎么修好它的?

當我將對象從 MongoDB(通過 Mongoose 方法:Model.find())直接發送到響應時,我遇到了這個問題。

          Claim.find()
            .then(claims => {
                context.res = {
                    status: 200,
                    headers: {
                        'Content-Type': 'application/json',
                        'Access-Control-Allow-Origin': '*'
                    },
                    body: claims
                };
                context.done();
            })

我必須將此主體對象更改為:

          Claim.find()
            .then(claims => {
                context.res = {
                    status: 200,
                    headers: {
                        'Content-Type': 'application/json',
                        'Access-Control-Allow-Origin': '*'
                    },
                    body: JSON.parse(JSON.stringify(claims))
                };
                context.done();
            })

我在不同情況下多次看到 502 錯誤。
大多數時候是我的編程錯誤/配置問題。
但是今天發現這個問題花了很多時間,所以在這里分享。

問題 #1

s3 = new AWS.S3();
AWS.config.loadFromPath(dirName1 + '\\aws-config.json');
s3.listObjectsV2(..);

在這里,雖然錯誤在第 1 行,但問題發生在第 3 行

解決辦法是:

AWS.config.loadFromPath(dirName1 + '\\aws-config.json');
s3 = new AWS.S3();
s3.listObjectsV2(..);

也就是說,加載 aws 配置后,我們需要創建 s3 新實例變量。

問題#2

正如這里給出的, https://stackoverflow.com/a/39240447/984471 ,是關於將文件寫入無法訪問的目錄,而您可以寫入 D:\\local\\Temp,我們不能寫入其他目錄,例如當前目錄或 D:\\

不幸的是,在上面的例子和我的其他例子中,Azure 函數存在而沒有任何登錄 azure 函數控制台,因此需要進行大量調試。

我也遇到了同樣的錯誤。 我在事件處理函數的末尾寫了“context.done(null,output)”,它工作正常。

就我而言,它是缺少WEBSITE_NODE_DEFAULT_VERSION應用程序設置(Node.js Windows 功能應用程序,高級和消費托管計划中均發生錯誤)。

如果您在 Azure 門戶中創建函數應用程序,應用程序設置會自動設置,但如果您使用 IaC 工具(在我的情況下為 Terraform),則需要明確設置它。

"WEBSITE_NODE_DEFAULT_VERSION" = "~14"

我有同樣的錯誤,我只是忘記添加“內容類型”標題“應用程序/json”。 添加標題后,它對我來說很好用

如果您收到 502:s 甚至缺少應用程序洞察日志條目...

健全性檢查:您是否部署了您的應用程序?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM