【问题标题】:IISNode and Express 3 yields http 403.13 errorIISNode 和 Express 3 产生 http 403.13 错误
【发布时间】:2016-04-16 02:43:10
【问题描述】:

我在我的 Win7 机器上本地设置 IIS 7 上的 IISNode。我按照网站上的说明进行操作,样本运行良好。

我在 IIS 管理器中创建了一个新网站和 AppPool 来运行一个全新的 Express 站点外壳。我添加了 web.config 以将 iisnode 模块绑定到我的起始 .js 文件。

当我浏览到默认路由 (/) 时,我收到 Http 403.14 错误(服务器配置为不列出目录的内容)。

我试图将 IISNode 示例目录重新映射到我的 Express 应用程序所在的位置,但发生了同样的错误。

如果我尝试转到不存在的路线,我会收到 Connect 的 404 错误消息 Cannot VERB ROUTE

我觉得我错过了一些简单且(希望很明显)的东西。

有没有人遇到过这种情况并可以提供一些见解?即使在我可以检查的情况下,在线查看也没有提供什么启示。

【问题讨论】:

    标签: node.js express iisnode


    【解决方案1】:

    我弄清楚我遇到了什么问题。在我的 web.config 中,我有默认的 IISNode 部分和处理程序部分,用于将 iisnode 模块映射到我的 app.js 文件。

    但是,在使用 Express 时,每条路由都必须经过该文件。因此,通过添加下面的重写部分,它解决了我的问题。

    <rewrite>
      <rules>
        <rule name="Catch All">
          <match url="/*" />
          <action type="Rewrite" url="app.js" />
        </rule>
      </rules>
    </rewrite>
    

    【讨论】:

    • 我尝试了您的解决方案,但仍然收到此错误。有什么想法吗?
    【解决方案2】:

    如需更高级的 URL 重写配置,请查看http://tomasz.janczuk.org/2012/05/yaml-configuration-support-in-iisnode.html 的 web.config 模板。此模板允许您将对静态内容的请求重定向到 IIS 静态文件处理程序,并保留通过 HTTP 访问 iisnode 日志的权限。

        <?xml version="1.0" encoding="utf-8"?>  
    <configuration>  
        <system.webServer>           
          <handlers>  
               <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>  
         </handlers>  
          <rewrite>  
               <rules>  
                    <rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">  
                         <match url="iisnode"/>  
                    </rule>  
                    <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">                      
                        <match url="^server.js\/debug[\/]?" />  
                    </rule>  
                    <rule name="StaticContent">  
                         <action type="Rewrite" url="public{{REQUEST_URI}}"/>  
                    </rule>  
                    <rule name="DynamicContent">  
                         <conditions>  
                              <add input="{{REQUEST_FILENAME}}" matchType="IsFile" negate="True"/>  
                         </conditions>  
                         <action type="Rewrite" url="server.js"/>  
                    </rule>  
               </rules>  
          </rewrite>  
       </system.webServer>  
     </configuration>
    

    上面的web.config有如下效果:

    1. 它将 server.js 指定为 node.js 应用程序的入口点。
    2. 它将映射到“public”子目录中物理文件的所有 URL 请求重定向到 IIS 静态文件处理程序。与从 node.js 应用程序中提供静态内容相比,使用 IIS 静态文件处理程序具有很大的性能优势。该处理程序利用 IIS 和 OS 低级缓存机制,提供卓越的性能。
    3. 它允许 IIS 将捕获 node.js 应用程序输出的日志文件作为静态文件提供,以便您可以通过 HTTP 访问它们。默认情况下,如果您的 server.js 入口点位于 http://example.com/server.js,则可以通过 http://example.com/iisnode 访问日志文件。
    4. 它在http://example.com/server.js/debug 公开了内置节点检查器调试器。详细了解如何使用 iisnode 进行调试。
    5. 它发送所有其他 HTTP 请求以由 server.js 中的 node.js 应用程序处理。

    【讨论】:

      【解决方案3】:

      在我的link 中找到更多信息,我在问题的底部有一个工作示例

      下面是项目配置

      在 server.js 的代码下方

       "use strict";
      
       var express = require('express');
       // determind what mode we are
       var env = process.env.NODE_ENV = process.env.NODE_ENV||'developemnt';
       var app = express();
       //configure the view engine
      
       app.set('views', __dirname + '/views');
       app.engine('html', require('ejs').renderFile);
       app.set('view engine', 'html');
      
       //app.use('/public', express.static(__dirname + '../public'));
      
       //the asterisk handles all routes includes javascript, css, html request...
       app.get('*', function (req , res) {
              res.render('index');
       });
       var PORT = 3030;
       app.listen((process.env.PORT!==undefined)?process.env.PORT:PORT);
       console.log('Listening to PORT : ' + process.env.PORT );
      

      index.html 下方

      <!doctype html>
      <!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
      <!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
      <!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
      <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
        <head>
          <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon"/>
        <base href="/">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width">
        </head>
        <body ng-app="idetikApp">
        <div ng-view=""></div>
          <script src="app/app.js"></script>
        </body>
      
      </html>
      

      web.config

      <?xml version="1.0" encoding="utf-8"?>
      <configuration>
          <system.webServer>
            <handlers>
                 <add name="iisnode" path="server/server.js" verb="*" modules="iisnode"/>
           </handlers>
            <rewrite>
                 <rules>
                      <rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
                           <match url="iisnode"/>
                      </rule>
                      <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
                          <match url="^server/server.js\/debug[\/]?" />
                      </rule>
                      <rule name="StaticContent">
                           <action type="Rewrite" url="public{{REQUEST_URI}}"/>
                      </rule>
                      <rule name="DynamicContent">
                           <conditions>
                                <add input="{{REQUEST_FILENAME}}" matchType="IsFile" negate="True"/>
                           </conditions>
                           <action type="Rewrite" url="server/server.js"/>
                      </rule>
                 </rules>
            </rewrite>
         </system.webServer>
       </configuration>
      

      app.js

      angular.module('idetikApp', [ 'ngResource', 'ngRoute']);
      
      angular.module('idetikApp').config(function ($routerProvider, $locationProvider) {
        $locationProvider.html5Mode(true);
        $routerProvider.when('/', {templateUrl: '/partials/main', controller:'mainctrl'})
      
      });
      
      angular.module('idetikApp').controller('mainctrl', function ($scope) {
        $scope.mayvar = "hello world"
      })
      

      和main.html

      <h1>this is a partial</h1>
      <h2>{{myvar}}</h2>
      

      还有我的文件夹结构

      但现在我在公共文件中找不到我的文件:(

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-07-23
        • 1970-01-01
        • 2019-10-22
        • 1970-01-01
        • 1970-01-01
        • 2015-12-17
        • 1970-01-01
        相关资源
        最近更新 更多