【发布时间】: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