【问题标题】:Node.js on Windows Azure IIS using IISNode: How to set startup file?使用 IISNode 在 Windows Azure IIS 上的 Node.js:如何设置启动文件?
【发布时间】:2015-10-15 15:43:53
【问题描述】:

我正在使用 IISNode 在 Windows Azure 上通过 IIS 服务 Node.js 文件。但是当我尝试使用http://127.0.0.1/mysite/node/ 访问服务器路径时,它会抛出以下错误

iisnode encountered an error when processing the request.

HRESULT: 0x2
HTTP status: 500
HTTP reason: Internal Server Error

并且在iisnode文件夹中生成的日志文件中显示以下错误:

Application has thrown an uncaught exception and is terminated:
Error: Cannot find module 'D:\Project\Files\mysite\node"'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (C:\Program Files\iisnode\interceptor.js:210:1)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)

但是当我尝试这条路径 http://127.0.0.1/mysite/node/app.js 时,它会执行 app.js 文件。但是,我不想在 URL 中显示 app.js 文件名。当我使用这个路径http://127.0.0.1/mysite/node/时,可以将此文件设置为默认文件或启动文件吗?


更新

下面是我的回答:

    <rule name="DynamicContent">
      <conditions>
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
      </conditions>
      <action type="Rewrite" url="node/main.js"/>
    </rule>

配置中的这段代码阻止调用任何 .net 文件,而是重定向到节点执行。仅当 URL 末尾包含 /node/(如 http://127.0.0.1/mysite/node/)时,我如何才能重定向到节点?

【问题讨论】:

    标签: javascript node.js azure iis iisnode


    【解决方案1】:

    我认为this 解决方案有效。

    正在评估中......


    更新

        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="node/main.js"/>
        </rule>
    

    config 中的这段代码阻止调用任何 .net 文件,并重定向到节点执行。

    如何仅当 URL 包含 /node/ 时才重定向到节点,例如 http://127.0.0.1/mysite/node/

    【讨论】:

      【解决方案2】:

      我们可以利用 web.config 文件中的 location 元素来决定特定目录中的所有文件都应该被视为 node.js 应用程序。

      这是我在 iis 中的站点目录图:

      这里是web.config的内容: <configuration> <location path="node"> <system.webServer> <handlers> <add name="iisnode" path="*.js" verb="*" modules="iisnode" /> </handlers>
      </system.webServer> </location> </configuration>

      http://localhost /mysite/node 这样的URL 将由iisnode 处理,如web.config 中配置的那样。

      而其他的不会受iisnode的影响,例如在这个测试中, http://localhost /mysite/php/index.php 仍在运行 PHP 脚本。

      更多信息,我们可以在Hosting node.js applications in IIS on Windows看到

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-02-20
        • 1970-01-01
        相关资源
        最近更新 更多