gpt4 book ai didi

node.js - Azure 应用服务中的 Docker 超时 - 使用 Nextjs

转载 作者:行者123 更新时间:2023-12-03 02:16:32 26 4
gpt4 key购买 nike

我在 azure 应用服务中使用 Linux 服务器。以前,我能够在应用程序服务上毫无问题地部署我的 nextjs 应用程序,并且运行得很好。然而,在另一次部署之后,docker 镜像突然超时。经过几个小时无法解决此问题后,我在 azure 上删除了该应用程序,重新创建它并进行部署,一切再次顺利进行。最近再次部署后,又出现了这种情况,docker镜像超时,我找不到问题所在。在有人问之前,是的,nextjs 正在端口 8080 上启动,并且我在应用程序服务中将 PORT 和 WEBSITES_PORT 应用程序变量设置为 8080,您还将在下面的日志中看到这一点。我的 web.config 和 server.js 文件位于根目录中。我还使用本教程在应用程序服务上发布了 nextjs 应用程序:https://parveensingh.com/next-js-deployment-on-azure-app-service/

以下是日志: enter image description here

这是我的 server.js:

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:

<!--
This configuration file is required if iisnode is used to run node processes behind
IIS or IIS Express. For more information, visit:

<https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config>
-->

<configuration>
<system.webServer>
<!-- Visit <http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx> for more information on WebSocket support -->
<webSocket enabled="false" />
<handlers>
<!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<!-- Do not interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\\/debug[\\/]?" />
</rule>

<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>

<!-- All other URLs are mapped to the node.js site entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>

<!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
<security>
<requestFiltering>
<hiddenSegments>
<remove segment="bin"/>
</hiddenSegments>
</requestFiltering>
</security>

<!-- Make sure error responses are left untouched -->
<httpErrors existingResponse="PassThrough" />

<!--
You can control how Node is hosted within IIS using the following options:
* watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
* node_env: will be propagated to node as NODE_ENV environment variable
* debuggingEnabled - controls whether the built-in debugger is enabled

See <https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config> for a full list of options
-->
<iisnode watchedFiles="web.config;*.js"/>
</system.webServer>
</configuration>

这是我的 package.json 脚本:

"scripts": {
"dev": "node server.js",
"build": "next build",
"start": "node server.js",
"lint": "next lint",
"test": "npx jest"
},

最佳答案

您可以尝试增加容器启动所允许的时间。

将 WEBSITES_CONTAINER_START_TIME_LIMIT 设置为 1800(最大值)

关于node.js - Azure 应用服务中的 Docker 超时 - 使用 Nextjs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71069803/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com