繁体   English   中英

IISNode和Express 3产生http 403.13错误

[英]IISNode and Express 3 yields http 403.13 error

我在Win7框上本地在IIS 7上设置IISNode。 我按照网站上的说明进行操作,样品工作正常。

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

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

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

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

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

有没有人碰到这个并且可以为我提供一些见解? 即使我可以查看,在线查看也没什么用。

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

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

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

有关更高级的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访问它们。 默认情况下,如果在http://example.com/server.js上访问了server.js入口点,则可以从http://example.com/iisnode访问日志文件。
  4. 它在http://example.com/server.js/debug中公开了内置的node-inspector调试器。 了解有关使用iisnode进行调试的更多信息。
  5. 它将所有其他HTTP请求发送到server.js中的node.js应用程序处理。

在我的链接中查找更多信息我有一个工作示例问题的底部

低于它的项目配置

在此输入图像描述

在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>

和我的文件夹结构

在此输入图像描述

但现在我无法在公共场所找到我的文件:(

在此输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM