【问题标题】:Can't get express.js working with IISNode无法让 express.js 与 IISNode 一起使用
【发布时间】:2013-12-06 17:11:24
【问题描述】:

我在服务器上设置了 IISNode,并按照指南获取了一个简单的 hello world node.js 应用程序运行它。它工作正常,并且可以通过互联网从外部访问。但是,当我尝试合并现有的 express 应用程序时,就好像 node/express 根本不存在。

这是我的 web.config 文件:

<configuration>
<system.webServer>

<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>

</system.webServer>
</configuration>

它位于 IIS 应用程序的根目录中,以及我的主要 express 文件 app.js。有趣的是,如果我去 localhost/TestApp/app.js,我会回来:

Cannot GET /TestApp/app.js

但是,如果我尝试使用不同的文件,例如 localhost/TestApp/public/htm/index.htm,我会取回位于那里的文件(如预期的那样以 HTML 格式)。另外,如果我尝试进行服务器调用(例如 localhost/TestApp/GetUsernames)。

更有趣的是,如果我弄乱了端口(例如 app.listen(process.env.PORT2 );),我会在尝试访问 localhost/TestApp.js 时得到这个:

> iisnode encountered an error when processing the request.
> 
> HRESULT: 0x2 HTTP status: 500 HTTP reason: Internal Server Error

如果端口是正确的 (app.listen(process.env.PORT2);),我得到 Cannot GET /TestApp/app.js,所以看起来 IISNode 正在执行 app.js(否则会怎样当我弄乱端口时失败),但似乎没有任何工作。

我该如何解决这个问题,或者至少诊断问题?

谢谢。

【问题讨论】:

    标签: node.js iis express iisnode


    【解决方案1】:

    您可能需要添加一个&lt;rewrite&gt; 部分来阐明如何路由请求:

    <rewrite>
            <rules>
                <!-- Don't 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 application entry point -->
                <rule name="DynamicContent">
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True" />
                    </conditions>
                    <action type="Rewrite" url="server.js" />
                </rule>
            </rules>
        </rewrite>
    

    从示例 Azure node.js 应用中提取。

    【讨论】:

    • 我遇到了类似的 iisnode 问题。
    猜你喜欢
    • 1970-01-01
    • 2014-10-31
    • 2018-01-02
    • 2016-11-14
    • 2015-02-01
    • 2019-05-10
    • 2017-11-20
    • 2011-05-24
    • 2019-05-17
    相关资源
    最近更新 更多