前言:最近因为项目原因,需要在IIS下部署node项目,在此之前,曾经部署过类似的项目,因此在这次部署还算比较顺利,只是在其中遇到了几个比较坑的问题,所以这次使用博客记录下来,如有园友遇到过类似问题,希望对你有所帮助。

一、前期准备

  1、node.js(下载地址:https://nodejs.org/en/),根据自己的需要安装对应版本

  2、iisnode(下载地址:https://github.com/tjanczuk/iisnode)

  3、IIS的URL Rewrite模块(下载地址:https://www.iis.net/downloads/microsoft/url-rewrite)

依次安装好以上软件,记录下node.js的安装路径(例如我的安装路径是:C:\software\nodejs),在后续中会用到。

如果需要测试iisnode是否安装成功,可以用

%programfiles%\iisnode\setupsamples.bat

执行后:

来安装iisnode自带的一个例子,安装完成后,访问:http://localhost/node,如果网页不能编译出现以下错误的解决办法:

The iisnode module is unable to start the node.exe process. Make sure the node.exe executable is available at the location specified in the system.webServer/iisnode/@nodeProcessCommandLine element of web.config. By default node.exe is expected in one of the directories listed in the PATH environment variable​

在要打开在页面所在文件夹下的web.config中添加以下内容:​

nodeProcessCommandLine=""%programfiles%\nodejs\node.exe"" ​interceptor=""%programfiles%\iisnode\interceptor.js"" />,注意配置文件里只允许有一个 iisnode 属性设置

如图

 

二、部署项目

在IIS下新建一个站点(此过程不在赘述),然后在项目下打开控制台,安装项目需要依赖的包,执行:

npm install

安装完成后会在项目中新增一个文件夹:

然后编辑web.config:

<configuration>
<system.webServer>
<!-- bin/www 是Express示例默认的启动程序 -->
<handlers>
<add name="iisnode" path="bin/www" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="myapp">
<match url="/*" />
<action type="Rewrite" url="bin/www" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

此时在浏览器中打开地址http://localhost/myapp/,将出现404错误,原因是bin目录是默认输出目录,默认不允许模块调用

HTTP 错误 404.8 - Not Found

请求筛选模块被配置为拒绝包含 hiddenSegment 节的 URL 中的路径。

解决办法:

在你的项目根目录下,新建一个index.js的文件,然后将bin/www里面的代码剪切过来,同时可以删除bin文件夹了,并且再次修改你的web.config文件,将入口程序改成index.js:

<configuration>
<system.webServer> <!-- indicates that the hello.js file is a node.js application
to be handled by the iisnode module --> <handlers>
<add name="iisnode" path="index.js" verb="*" modules="iisnode" resourceType="Unspecified" requireAccess="Script" preCondition="bitness64" />
</handlers> <rewrite>
<rules>
<rule name="all">
<match url="/*" />
<action type="Rewrite" url="index.js" />
</rule>
</rules>
</rewrite> <iisnode
node_env="%node_env%"
nodeProcessCountPerApplication="1"
maxConcurrentRequestsPerProcess="1024"
maxNamedPipeConnectionRetry="100"
namedPipeConnectionRetryDelay="250"
maxNamedPipeConnectionPoolSize="512"
maxNamedPipePooledConnectionAge="30000"
asyncCompletionThreadCount="0"
initialRequestBufferSize="4096"
maxRequestBufferSize="65536"
watchedFiles="*.js;node_modules\*;routes\*.js;views\*.jade"
uncFileChangesPollingInterval="5000"
gracefulShutdownTimeout="60000"
loggingEnabled="true"
logDirectory="iisnode"
debuggingEnabled="true"
debugHeaderEnabled="false"
debuggerPortRange="5058-6058"
debuggerPathSegment="debug"
maxLogFileSizeInKB="128"
maxTotalLogFileSizeInKB="1024"
maxLogFiles="20"
devErrorsEnabled="true"
flushResponse="false"
enableXFF="false"
configOverrides="iisnode.yml"
nodeProcessCommandLine="C:\software\nodejs\node.exe"
promoteServerVars="REMOTE_ADDR" /> <defaultDocument>
<files>
<add value="index.js" />
</files>
</defaultDocument> <!-- One more setting that can be modified is the path to the node.exe executable and the interceptor: <iisnode
nodeProcessCommandLine="&quot;%programfiles%\nodejs\node.exe&quot;"
interceptor="&quot;%programfiles%\iisnode\interceptor.js&quot;" /> --> </system.webServer>
</configuration>

此时你就可以运行你的项目了,如果在运行的时候输出如下错误:

iisnode encountered an error when processing the request.

请检查你的index.js文件的require路径是否正确:

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

正常情况下,此时你的项目就可以正常运行了,但是!!!还没完!!,最坑人的地方来了,你的项目可能会一直报一下错误:

iisnode encountered an error when processing the request.

HRESULT: 0x2
HTTP status: 500
HTTP reason: Internal Server Error
You are receiving this HTTP 200 response because system.webServer/iisnode/@devErrorsEnabled configuration setting is 'true'. In addition to the log of stdout and stderr of the node.exe process, consider using debugging and ETW traces to further diagnose the problem. The node.exe process has not written any information to stderr or iisnode was unable to capture this information. Frequent reason is that the iisnode module is unable to create a log file to capture stdout and stderr output from node.exe. Please check that the identity of the IIS application pool running the node.js application has read and write access permissions to the directory on the server where the node.js application is located. Alternatively you can disable logging by setting system.webServer/iisnode/@loggingEnabled element of web.config to 'false'.

找了很久错误,始终以为是哪个环节安装好,或者依赖包没有安装正确,始终没有解决,在快绝望的时候,终于在stackoverflow上找到了一位外国网友记录这个错误解决办法:

地址:https://stackoverflow.com/questions/24028537/iisnode-encountered-an-error-when-processing-the-request/24038377

老铁们!看到这个解决办法我也是想哭了,还有这个??于是修改了项目的user权限,问题就迎刃而解了。

三、总结

永远不要忽略细节!!!

记录一次使用iisnode部署node项目遇到的坑!的更多相关文章

  1. 在阿里云创建子域名,配置nginx,使用pm2部署node项目到ubuntu服务器

    配置域名 在阿里云找到主域名 进入主域名之后,右上角添加解析,添加子域名, 记录类型选择cname,主机记录填写子域名的名称,记录值为主域名,至此阿里云已经配置好了. 检查nginx安装 首先检查服务 ...

  2. 在Linux服务器上部署node项目(git部署,forever持续运行,配置SSL证书)

    一.环境部署 1.下载安装包: wget https://nodejs.org/dist/v9.9.0/node-v9.9.0-linux-x64.tar.xz 2.解压并进入目录: xz -d no ...

  3. CentOS 7 部署 node 项目

    CentOS 7 部署 node 项目 安装 node 环境 方法一:使用 wget 的方式下载压缩包进行解压 淘宝node镜像地址,进入地址选择自己想要安装的版本 wget https://npm. ...

  4. 宝塔linux部署node项目

    1.安装宝塔linux之后,按需配置,我的是nginx,不是apq的. 2.下载pm2管理器 3.添加站点,将node项目从localhost打包到到站点,node_modules这个无需打包,这个依 ...

  5. weblogic中部署SSH项目遇到的坑

    总结将SSH项目部署到weblogic遇到的坑.项目中是SSH,另外还用到了webservice.quartz等框架.在tomcat部署是可以的,现在总结部署到weblogic遇到的坑. 在这里说一下 ...

  6. 使用pm2自动化部署node项目

    1.pm2简介 pm2(process manager)是一个进程管理工具,维护一个进程列表,可以用它来管理你的node进程,负责所有正在运行的进程,并查看node进程的状态,也支持性能监控,负载均衡 ...

  7. Docker搭建部署Node项目

    前段时间做了个node全栈项目,服务端技术栈是 nginx + koa + postgresql.其中在centos上搭建环境和部署都挺费周折,部署测试服务器,接着上线的时候又部署生产环境服务器.这中 ...

  8. jenkins部署node项目

    docker run -d --name jenkins -p 8081:8080 -v /home/jenkins_home:/home/jenkins_home jenkins

  9. 那些在BAE上部署node.js碰到的坑

    在BAE上使用node.js半年多了,其中碰到了不少因为BAE云环境限制碰到的坑 写下来大家碰到了,也不用那么麻烦的去看好几天代码了,直接对症下药 官方公布的坑有: BAE是使用package.jso ...

随机推荐

  1. *P3694 邦邦的大合唱站队[dp]

    题目描述 N个偶像排成一列,他们来自M个不同的乐队.每个团队至少有一个偶像. 现在要求重新安排队列,使来自同一乐队的偶像连续的站在一起.重新安排的办法是,让若干偶像出列(剩下的偶像不动),然后让出列的 ...

  2. test20190901 NOI2019 模拟赛

    0+0+0=0.还是太菜,看不出题型. Masodik 你要从 (0,0) 点走到 (n,m),每次只能往 x 轴或者 y 轴正方向移动一个单位距离.从 (i,j) 移动到 (i,j+1) 的代价为 ...

  3. linux下使用rzsz实现文件的上传和下载

    新搞的云服务器用SecureCRT不支持上传和下载,没有找到rz命令.记录一下如何安装rz/sz命令的方法. 一.工具说明 在SecureCRT这样的ssh登录软件里, 通过在Linux界面里输入rz ...

  4. 权限管理(chown、chgrp、umask)

    对于文件或目录的权限的修改,只能管理员和文件的所有者拥有此权限,但是对于文件或目录的的所有者的更改,只有管理员拥有此权限(虽然普通用户创建的文件或目录,用户也不能修改文件或目录的所有者). 1.cho ...

  5. Approximate Search

    题目链接:Gym-101492H 动态规划,应该是比较基础的,可是自己就是不会QAQ.... /* 把使用机会当成“花费” */ # include <iostream> # includ ...

  6. 【POJ2996】Help Me with the Game

    题目传送门 本题知识点:模拟(如果对国际象棋不熟悉的同学可以先百度一下) 题意很简单,就是让我们找出白棋跟黑棋每枚棋子的位置,并要按照一定的顺序输出( K -> Q -> R -> ...

  7. CNN中各类卷积总结:残差、shuffle、空洞卷积、变形卷积核、可分离卷积等

    CNN从2012年的AlexNet发展至今,科学家们发明出各种各样的CNN模型,一个比一个深,一个比一个准确,一个比一个轻量.我下面会对近几年一些具有变革性的工作进行简单盘点,从这些充满革新性的工作中 ...

  8. 无法定位程序输入点到xxx.dll

    Q:安装pytorch时报错无法定位程序输入点到Anaconda3\Library\bin\libssl-1_1-x64.dll A:下载libssl-1_1-x64.dll覆盖bin下的文件 下载地 ...

  9. Web前端开发规范 之html命名规范

    1.文件名称命名规则 统一用小写的英文字母.数字和下划线,不得包含汉字空格和特殊符号 2.索引文件命名 一般用index为名字  如index.html  index.jsp 3.各子页面的命名规则 ...

  10. LOL佐伊官方手办

      花199元在某宝上买的官方正版佐伊手办终于到了,话不多说直接上图!   虽然脸有点不切实际的大,但还是很可爱~