【问题标题】:How to specify a file path in handler tag in web.config如何在 web.config 的处理程序标记中指定文件路径
【发布时间】:2018-09-03 21:01:01
【问题描述】:

我正在尝试在 Azure 云上运行一个简单的 node.js 应用程序。

我基本上按照以下网站上的说明进行操作。

-创建Web应用程序- https://code.visualstudio.com/tutorials/app-service-extension/create-app

-Web应用程序的部署- https://code.visualstudio.com/tutorials/app-service-extension/deploy-app

为了在 Azure(IIS) 上运行它,我在根文件夹中添加了 web.config 和 server.js,如下所示。 added 2 files

文件内容如下。 [web.config]

<configuration>
<system.webServer>
      <handlers>

        <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
        <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
      </handlers>
      <rewrite>
        <rules>

          <!-- All URLs are mapped to the node.js site entry point -->          
          <rule name="DynamicContent">
            <match url="/*" />
            <action type="Rewrite" url="server.js"/>
          </rule>

        </rules>
      </rewrite>
</system.webServer>
</configuration> 

[服务器.js] 以下仅显示部分代码。

#!/usr/bin/env node

/**
 * Module dependencies.
 */

var app = require('./app');
var debug = require('debug')('myexpressapp:server');
var http = require('http');

/**
 * Get port from environment and store in Express.
 */

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

/**
 * Create HTTP server.
 */

部署到 Azure(IIS) 后,Web 应用程序成功运行。但是,我想使用 bin/www 文件而不是 server.js。实际上,我通过处理 bin/www 文件在根文件夹中创建了 server.js 文件。 为了直接使用bin/www,我把web.config改成如下,但是这样会导致报错。浏览器显示错误;“您要查找的资源已被删除、更改名称或暂时不可用。”似乎找不到 www 文件。我写路径的方式有问题吗?

<configuration>
<system.webServer>
      <handlers>

        <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
        <add name="iisnode" path="bin/www" verb="*" modules="iisnode"/>
      </handlers>
      <rewrite>
        <rules>

          <!-- All URLs are mapped to the node.js site entry point -->          
          <rule name="DynamicContent">
            <match url="/*" />
            <action type="Rewrite" url="bin/www"/>
          </rule>

        </rules>
      </rewrite>
</system.webServer>
</configuration> 

我会给予任何帮助。

【问题讨论】:

  • “根文件夹”?哪一个?通常你不能,因为规则是从你的站点文件夹执行的,并且“bin/www”必须在你的站点文件夹下。如果要更改服务器级别,则必须使用“applicationHost.xdt”。
  • 非常感谢您的回答。我很抱歉造成混乱。它实际上是“wwwroot”文件夹,我的意思是“root”。 web.config 存在于这个 wwwroot 文件夹中。在 web.config 文件中,我试图引用 wwwroot/bin/www 文件,但这基本上不能做到吗?如果我想在web.config中写一个文件路径,引用的文件必须和web.config在同一个文件夹中?
  • Windows 使用“\”而不是“/”,所以我认为您应该使用“bin\www”。
  • 非常感谢您的回答。我试过了,但没有用。

标签: node.js azure iis path web-config


【解决方案1】:

我能够解决问题。 我将文件夹的名称从“bin”更改为其他名称,它起作用了。我试图理解为什么“bin”这个名字不起作用……是因为“bin”是服务器保留的,不能使用吗?如果有人可以让我知道任何可能的原因,我会很高兴...

【讨论】:

    猜你喜欢
    • 2018-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-19
    • 2014-07-09
    • 1970-01-01
    • 1970-01-01
    • 2014-01-15
    相关资源
    最近更新 更多