繁体   English   中英

无法在 Azure 应用服务上运行 Next.js 应用

[英]Unable to get Next.js app running on Azure App Service

我正在尝试让最基本的 Next.js 应用程序在 Azure 应用服务中运行(URL 是https://asmkp-rich-test2.azurewebsites.net/ )。

我可以让一个基本的 Node 应用程序运行良好,从 git 部署(存储库在这里: https://github.com/Richiban/nextjs-azure-test ,分支是release )。

但是,我所做的任何事情都不会运行此应用程序。

如果您点击该网址,您将看到:

The page cannot be displayed because an internal server error has occurred.

除了以下内容之外,std 输出中没有任何内容:

Node version: v10.6.0
Done
[5:45:37 PM] Compiling server
[5:45:38 PM] Compiling client
[5:45:38 PM] Compiled server in 1000ms
[5:45:41 PM] Compiled client in 3s
 DONE  Compiled successfully in 3859ms5:45:41 PM

App prepared
Got handle
Ready on http://localhost:8080

除了以下内容之外,错误输出中没有任何内容:

(node:22980) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.

您可以在 git repo 中看到我的server.js ,但我也会将它包含在此处以便于阅读:

 const http = require("http"); const next = require("next"); const port = parseInt(process.env.PORT, 10) || 3000; const dev = process.env.NODE_ENV !== "production"; const app = next({ dev }); console.log("Node version: " + process.version); app.prepare() .then(() => { console.log("App prepared"); const handle = app.getRequestHandler(); console.log("Got handle"); http.createServer(function(req, res) { console.log(`Processing incoming request`); try { handle(req, res).catch(function(e) { console.log(`Error caught3: ` + e); console.log(e); }); console.log(`Incoming request done`); } catch (e) { console.log(`Error caught: ` + e); console.log(e); } }).listen(port); console.log(`> Ready on http://localhost:${port}`); }) .catch(function(e) { console.log(`Error caught2: ` + e); console.log(e); }); console.log("Done");

正如您可能从我填入的日志数量中看到的那样,我今天对此无能为力。

所以,总而言之,我有一个最简单的 Next.js 应用程序,我正在使用 Git 将其部署到 Azure 应用程序服务,虽然它在我的机器上运行得很好,但在 Azure 中我收到一条毫无意义的错误消息,看起来像没有更多细节。

请帮忙。

DeprecationWarning 是一个红鲱鱼。 您看到此一般错误是因为 iisnode 无法与节点进程通信。

process.env.PORT 在使用 iisnode 时实际上是一个管道名称,因此 parseInt 失败并使用您的后备端口 3000。这意味着您的 next.js 应用程序正在侦听错误的端口。 相应地更新您设置端口号的行:

 const port = process.env.PORT;

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM