无法在 Azure 应用服务上获取 Next.js 应用 运行
Unable to get Next.js app running on Azure App Service
我正在尝试在 Azure 应用服务中获取最基本的 Next.js 应用程序 运行ning(URL 是 https://asmkp-rich-test2.azurewebsites.net/)。
我可以得到一个基本的 Node 应用程序 运行ning 很好,从 git 部署(存储库在这里:https://github.com/Richiban/nextjs-azure-test,分支是 release
)。
但是,无论我做什么,都无法将此应用程序升级到 运行。
如果你点击 URL 你会看到:
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 存储库中看到我的 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;
我正在尝试在 Azure 应用服务中获取最基本的 Next.js 应用程序 运行ning(URL 是 https://asmkp-rich-test2.azurewebsites.net/)。
我可以得到一个基本的 Node 应用程序 运行ning 很好,从 git 部署(存储库在这里:https://github.com/Richiban/nextjs-azure-test,分支是 release
)。
但是,无论我做什么,都无法将此应用程序升级到 运行。
如果你点击 URL 你会看到:
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 存储库中看到我的 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;