【发布时间】:2020-10-20 00:11:55
【问题描述】:
我有一个使用 IISNode 运行 Node.js 应用程序的 Azure 应用服务。问题是 process.env.PORT 未定义。我读过 IISNode 使用了一个名为 命名管道 的东西,并且端口信息可能不容易读取(?),但在我的情况下,我只是未定义。
我尝试部署的项目可以从GitHub找到。
我确实定义了一个 Web.config 文件,它看起来像这样:
<handlers>
<!-- indicates that the app.js file is a node.js application to be handled by the iisnode module -->
<add name="iisnode" path="index.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<!-- Don't interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^index.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 application entry point -->
<rule name="DynamicContent">
<match url="/*" />
<action type="Rewrite" url="index.js" />
</rule>
</rules>
</rewrite>
<!-- You can control how Node is hosted within IIS using the following options -->
<!--<iisnode
node_env="%node_env%"
nodeProcessCountPerApplication="1"
maxConcurrentRequestsPerProcess="1024"
maxNamedPipeConnectionRetry="3"
namedPipeConnectionRetryDelay="2000"
maxNamedPipeConnectionPoolSize="512"
maxNamedPipePooledConnectionAge="30000"
asyncCompletionThreadCount="0"
initialRequestBufferSize="4096"
maxRequestBufferSize="65536"
watchedFiles="*.js"
uncFileChangesPollingInterval="5000"
gracefulShutdownTimeout="60000"
loggingEnabled="true"
logDirectoryNameSuffix="logs"
debuggingEnabled="true"
debuggerPortRange="5058-6058"
debuggerPathSegment="debug"
maxLogFileSizeInKB="128"
appendToExistingLog="false"
logFileFlushInterval="5000"
devErrorsEnabled="true"
flushResponse="false"
enableXFF="false"
promoteServerVars=""
/>-->
<iisnode watchedFiles="*.js;node_modules\*;routes\*.js;views\*.jade;views\account\*.jade;iisnode.yml" />
</system.webServer>
我编写了一个 Kudu 脚本,它将构建资产并将它们复制到 %DEPLOYMENT_TARGET%。
我在这里缺少什么?任何帮助表示赞赏!
更新
我花了好几天的时间来找出进程无法启动的原因,因此未定义环境变量。我在 15 分钟内就在 Heroku 上启动并运行了应用程序,所以我想这仍然是个谜(至少对我来说)。
【问题讨论】:
-
尝试使用 Kudu 进程浏览器查看 Node 进程的 env 变量。您应该看到 PORT 的值类似于
\\.\pipe\e317fe18-7017-4a09-84fb-773a54cf0738。另外,请尝试使用普通的 Node 应用程序进行隔离。 -
@DavidEbbo 有没有办法查看 IIS 日志?我只能在列表中看到 SCM 进程,但我不知道 IISNode / IIS 是否正在尝试启动我的应用程序,即使我定义了 web.config
-
试试this,看看有没有有趣的日志。如上所述,请用一个简单的案例进行隔离。
标签: node.js azure iis azure-web-app-service iisnode