我很高兴获得有关如何调试此问题的任何提示?
next.js 在 Windows Azure Web App 上的 Node.js 18.19.1 上独立运行。
应用程序在本地启动(通过 /build/standalone 文件夹)
package.json 有一个:“start”:“node server.js”
端口3000表示process.env.PORT不是azure设置的?
(node:6588) [DEP0005] DeprecationWarning:由于安全和可用性问题,Buffer() 已被弃用。请改用 Buffer.alloc()、Buffer.allocUnsafe() 或 Buffer.from() 方法。 (使用
node --trace-deprecation ...
显示警告的创建位置)
⨯ 启动服务器失败
错误:监听未知:未知错误 0.0.0.0:3000
在 Server.setupListenHandle [as _listen2] (节点:net:1817:16)
在listenInCluster(节点:net:1865:12)
在 doListen(节点:net:2014:7)
在 process.processTicksAndRejections (节点:内部/进程/task_queues:83:21){
代码:“未知”,
错误号:-1,
系统调用:'听',
地址:'0.0.0.0',
端口:3000
}
我创建了示例 Nextjs 独立应用程序并部署到 Azure Web 应用程序服务窗口。
在 next.config 文件中,我已将输出设置为独立。
next.config.mjs:
const nextConfig = {
output: 'standalone',
}
export default nextConfig;
为了将 nextjs 应用程序部署到 Azure Web App Windows,我将 web.config 和 server.js 文件添加到项目的根目录。
为了避免错误,请使用下面的 server.js 文件。
服务器.js:
const { createServer } = require("http");
const next = require("next");
const port = process.env.PORT || 3000;
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
createServer((req, res) => {
handle(req, res);
}).listen(port, (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`);
});
});
web.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
WebSocket support -->
<webSocket enabled="false" />
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?" />
</rule>
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>
<httpErrors existingResponse="PassThrough" />
<iisnode watchedFiles="web.config;*.js"/>
</system.webServer>
</configuration>
我通过VS代码将nextjs应用程序部署到Azure应用程序服务。
Azure Web 应用程序输出: