【问题标题】:Docker timing out in Azure App Service - using NextjsAzure 应用服务中的 Docker 超时 - 使用 Nextjs
【发布时间】:2022-02-11 06:54:17
【问题描述】:

我在 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/

以下是日志:

这是我的 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"
  },

【问题讨论】:

  • 抱歉图片质量问题,您可以在另一个标签页中打开图片以更好的分辨率查看
  • 我在 Linux 应用服务上运行 ASP.NET Core 容器时遇到了许多不同的问题,因此我改为迁移到 AKS。 Linux 应用服务在我看来总是半成品。

标签: node.js azure docker next.js azure-web-app-service


【解决方案1】:

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

将 WEBSITES_CONTAINER_START_TIME_LIMIT 设置为 1800(这是最大值)

【讨论】:

  • 这对我有用,因为我实际上得到了一个关于导致超时的真正错误的日志。我猜较早的时间限制不足以使该日志发生。然后我能够修复它,它不再超时。
  • 真正的错误是什么?
  • @AndrewGee 我在根目录(例如localhost:300/[dynamicPage])中拥有的动态页面的 getServerSideProps 因某种原因被调用,而 docker 称为“下一个开始”,但我得出的结论是你不应该将动态页面放在根目录下,它应该放在某个子目录下,这对我有用。
猜你喜欢
  • 1970-01-01
  • 2020-01-18
  • 2022-06-10
  • 2019-08-30
  • 2017-10-02
  • 2021-02-23
  • 2019-07-11
  • 2020-10-03
  • 1970-01-01
相关资源
最近更新 更多