【问题标题】:Azure Web App doesn't start node serverAzure Web App 不启动节点服务器
【发布时间】:2016-07-19 17:47:12
【问题描述】:

我正在通过 bitbucket 发布我的 typescript node.js/express azure 应用程序,看起来一切都在正确编译,但是 azure 没有启动应用程序。

一个可重复的存储库是here。我尝试将应用程序克隆到一个新的本地目录,然后运行 ​​deploy.cmd 并在输出文件夹中调用 node start,效果很好。

【问题讨论】:

  • 您的回购链接无效
  • 已修复,格式错误
  • @Somkun 已修复,您解决了问题吗?如果是这种情况,您应该删除此问题。
  • 修复了断开的链接

标签: node.js azure typescript


【解决方案1】:

由于 Azure Web 应用程序上的 node.js 应用程序未侦听经典号码端口,因此在 iisnode 侦听的默认端口上响应 Web 请求。

您可以尝试修改您的main.ts 脚本:

let server: Server = new Server(process.env.PORT || 3000);

Azure Web Apps上对node.js应用程序的请求是通过iisnode处理的,你需要在根目录下创建一个web.config配置文件来配置入口文件,在你的场景中是bin\main.js .

web.config 内容示例:

<?xml version="1.0" encoding="utf-8"?>
<!-- 
     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 bin/main.js file is a node.js site to be handled by the iisnode module -->
               <add name="iisnode" path="bin/main.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="^bin/main.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="bin/main.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

               To debug your node.js application:
                 * set the debuggingEnabled option to "true"
                 * enable web sockets from the portal at https://manage.windowsazure.com/#Workspaces/WebsiteExtension/Website/garynodedeploy/configure
                 * browse to https://garynodedeploy.azurewebsites.net/bin/main.js/debug/

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

你可以参考https://github.com/tjanczuk/iisnode了解更多关于iisnode的信息。

【讨论】:

  • 我错过了端口信息。 web.config 不是必需的,谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-04-05
  • 2012-08-23
  • 2017-07-31
  • 2019-10-30
  • 2017-08-06
  • 2016-06-09
  • 1970-01-01
相关资源
最近更新 更多