以下所有内容都是在iis服务器配置成功的基础上
-
安装 node.js,官网下载 node.exe(用express的再安装express),这步略过。
-
安装 iisnode,https://github.com/tjanczuk/iisnode/wiki/iisnode-releases,IIS运行 node.js 的关键。
-
安装 url-rewrite,http://www.iis.net/downloads/microsoft/url-rewrite
-
将项目放到指定文件夹下,在这个文件夹下新建一个web.config文件。
web.config文件中的内容
<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:\Program Files\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=""%programfiles%\nodejs\node.exe""
interceptor=""%programfiles%\iisnode\interceptor.js"" />
-->
</system.webServer>
</configuration>
其中里的path="index.js"对应node项目入口文件路径
nodeProcessCommandLine=“C:\Program Files\nodejs\node.exe” 这个是node.exe的安装路径
5.index.js中端口监听原先写法是 server.listen(8080) 改成 server.listen(process.env.PORT||8080)