【问题标题】:Node.js app in Azure subfolder not runningAzure 子文件夹中的 Node.js 应用程序未运行
【发布时间】:2016-08-17 08:10:16
【问题描述】:

我们已经和我的一位同事一起尝试了所有方法,但无法正常工作:( 我们在 Azure 中有一个 Web 应用程序——一个 MVC 应用程序。我们想在其中添加一个博客作为子文件夹,但现在我们使用一个非常简单的快速应用程序进行测试。

基本上,我们有主 MVC 应用程序。 我已经尝试将我的小型测试 node.js 应用程序移动到 site\test 和 site\wwwroot\test。 有一个虚拟应用程序/test 指向站点/test。 (来自 Azure 门户应用程序设置)。

在测试文件夹内,web.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <system.webServer>
        <handlers>
            <add name="iisnode" path="index.js" verb="*" modules="iisnode" />
        </handlers>
        <rewrite>
            <rules>
                <rule name="DynamicContent">
                    <action type="Rewrite" url="index.js" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

index.js

var express = require('express');
var app = express();

console.log(1);

app.get('/', function (req, res) {
  res.send('Hello World!');
});

app.listen(process.env.PORT || 3000, function () {
  console.log('Test is live');
});

package.json

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "express": "^4.14.0"
  }
}

我尝试打开http://MySite.azurewebsites.net/test/,然后从FTP打开主站点并转到LogFiles/DetailedErrors,出现两个错误:

HTTP Error 500.1000 - Internal Server Error
Detailed Error Information:
Module     iisnode
Notification       ExecuteRequestHandler
Handler    iisnode
Error Code     0x8007000d
Requested URL      http://MySite:80/test/index.js
Physical Path      D:\home\site\wwwroot\test\index.js
Logon Method       Anonymous
Logon User     Anonymous

HTTP Error 403.14 - Forbidden
Detailed Error Information:
Module     DirectoryListingModule
Notification       ExecuteRequestHandler
Handler    StaticFile
Error Code     0x00000000
Requested URL      http://MySite:80/test/
Physical Path      D:\home\site\wwwroot\test\
Logon Method       Anonymous
Logon User     Anonymous

最后,这是主应用程序 web.config。我怀疑它可能是解决问题的关键:

<?xml version="1.0" encoding="utf-8"?>
<configuration>  
  <configSections>    
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <sectionGroup name="jsEngineSwitcher">
      <section name="core" type="JavaScriptEngineSwitcher.Core.Configuration.CoreConfiguration, JavaScriptEngineSwitcher.Core" />
      <section name="msie" type="JavaScriptEngineSwitcher.Msie.Configuration.MsieConfiguration, JavaScriptEngineSwitcher.Msie" />
      <section name="v8" type="JavaScriptEngineSwitcher.V8.Configuration.V8Configuration, JavaScriptEngineSwitcher.V8" />
    </sectionGroup>
  </configSections>  
  <connectionStrings>
    some conn strings
  </connectionStrings>    
  <location path="." inheritInChildApplications="false">
    <appSettings>
      <add key="webpages:Version" value="3.0.0.0" />
      <add key="webpages:Enabled" value="false" />
      <add key="ClientValidationEnabled" value="true" />
      <add key="UnobtrusiveJavaScriptEnabled" value="true" />      
      <add key="webpages:Enabled" value="true" />
      <add key="webpages:Version" value="3.0.0.0" />
    </appSettings>
  </location>
  <location path="." inheritInChildApplications="false">
    <system.web>      
      <authentication mode="None" />
      <compilation debug="true" targetFramework="4.5" />
      <httpRuntime targetFramework="4.5" />
      <httpHandlers>
        <add path="*.png" verb="*" type="System.Web.StaticFileHandler" validate="true" />
        <add path="*.js" verb="*" type="System.Web.StaticFileHandler" validate="true" />        
      </httpHandlers>      
    </system.web>
  </location>
  <location path="." inheritInChildApplications="false">
    <system.webServer>    
      <validation validateIntegratedModeConfiguration="false" />
      <modules runAllManagedModulesForAllRequests="true">
        <remove name="FormsAuthentication" />
      </modules>
      <staticContent>
        <remove fileExtension=".eot" />
        <remove fileExtension=".ttf" />
        <remove fileExtension=".otf" />
        <remove fileExtension=".woff" />
        <remove fileExtension=".woff2" />
        <mimeMap fileExtension=".eot" mimeType="application/vnd.ms-fontobject" />
        <mimeMap fileExtension=".ttf" mimeType="font/ttf" />
        <mimeMap fileExtension=".otf" mimeType="font/otf" />
        <mimeMap fileExtension=".woff" mimeType="application/font-woff" />
        <mimeMap fileExtension=".woff2" mimeType="application/font-woff" />
        <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="14.00:00:00" />
      </staticContent>
      <security>
        <requestFiltering>
          <hiddenSegments>
            <add segment="ClearScript.V8" />
          </hiddenSegments>
        </requestFiltering>
      </security>
      <handlers>
        <remove name="Babel" />
        <add name="Babel" verb="GET" path="*.jsx" type="React.Web.BabelHandlerFactory, React.Web" preCondition="integratedMode" />
      </handlers>     
      <directoryBrowse enabled="false" />
    </system.webServer>
  </location>  
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.1.0" newVersion="3.0.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <jsEngineSwitcher xmlns="http://tempuri.org/JavaScriptEngineSwitcher.Configuration.xsd">
    <core>
      <engines>
        <add name="MsieJsEngine" type="JavaScriptEngineSwitcher.Msie.MsieJsEngine, JavaScriptEngineSwitcher.Msie" />
        <add name="V8JsEngine" type="JavaScriptEngineSwitcher.V8.V8JsEngine, JavaScriptEngineSwitcher.V8" />
      </engines>
    </core>
  </jsEngineSwitcher>
</configuration>

我们已经尝试了所有可以在网上找到的方法,但没有任何效果 :( 非常感谢一些帮助!

【问题讨论】:

    标签: node.js azure


    【解决方案1】:

    这里是IIS, Node.js, and Web Application with IISNode not configured right with Virtual Directory的答案,和你的情况一样。我在本地测试了这个答案,效果很好。

    我构建了一个空的 MVC 应用程序,并将一个简单的 expressjs 应用程序放入其中,web.confighttp://tstrimple.com/express-4-azure-websites/ 类似。

    而且我没有在 MVC 的 web.config 文件中配置任何位置标记。

    如有任何疑问,请随时告诉我。

    【讨论】:

    • 谢谢,加里。我已经从第一个链接尝试了 web.config,从主应用程序中删除了该位置。无论如何,什么都没有让它工作。在我的本地机器上一切都很好,但在 Azure 中却不行。我不断收到 HTTP 500.1000 详细错误信息:Module iisnode Notification ExecuteRequestHandler Handler iisnode Error Code 0x8007000d Requested URL Site:80/test/index.js Physical Path D:\home\site\wwwroot\test\index.js Logon Method Anonymous Logon User Anonymous 讨厌它,但是将使用 WP :( ps 第二个链接:“不再需要以下内容。”
    • github.com/Walk4Muscle/ExpressInAspMVC,这是我的测试项目,在本地和 Azure Web 应用程序上都可以正常工作。希望对你有帮助。
    • 谢谢,加里。不知道为什么它不在我的本地机器(即节点)上运行。我已通过 VS 2015 将项目发布到 Azure。通过 FileZilla 添加节点文件夹。从应用程序设置创建了一个虚拟应用程序。我得到的只是:详细的错误信息:模块 AspNetInitializationExceptionModule 通知 BeginRequest 处理程序 iisnode 错误代码 0x00000000 请求的 URL NodeTestFMC:80/node/server.js 物理路径 D:\home\site\wwwroot\node\server.js 登录方法尚未确定登录用户尚未确定
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-05-26
    • 2011-03-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 1970-01-01
    相关资源
    最近更新 更多