IIS环境下增加Node.js站点

2019-02-20 17:48:10 5741

     假设,客户已经在使用IIS运行多站点,此时再增加一个Node.js站点必须绑定域名,80端口已经被占用,就必须使用这种方式,使用IISnode模块实现。同时需要辅以URL Rewrite。分享文章如下:


iisnode

IIS什么的就不多说了,直接说主要用的东西,iisnode下载地址

另外还需要安装URL Rewrite
安装iisnode之后,可以用%programfiles%\iisnode\setupsamples.bat来安装一个例子,然后访问http://www.landui.com/node
安装完之后,新建一个站点,监听80端口,配置好自己的域名。

web.config

web.config配置可以参考github中samples中的configuration.

<configuration>
    <system.webServer>
        <handlers>
            <add name="iisnode" path="launch.js" verb="*" modules="iisnode" resourceType="Unspecified" requireAccess="Script" />
        </handlers>
 
        <rewrite>
            <rules>
                <rule name="all">
                    <match url="/*" />
                    <action type="Rewrite" url="launch.js" />
                </rule>
            </rules>
        </rewrite>
        
        <iisnode
      nodeProcessCommandLine="&quot;C:\Program Files\nodejs\node.exe&quot;" 
      interceptor="&quot;C:\Program Files\iisnode\interceptor.js&quot;" 
      promoteServerVars="REMOTE_ADDR"/>
    </system.webServer></configuration>

launch.js

因为bin会在url重写时被IIS屏蔽,因此不能直接把url重写到bin/www上,因此需要增加一个中间文件,或者修改bin目录的名字(当然是不推荐的)。
launch.js很简单,只需要require一下bin/www.

require('./bin/www');

接下来重启站点就可以了。

500.19

如果运行的时候出现如下错误:

500.19
配置错误 不能在此路径中使用此配置节。如果在父级别上锁定了该节,便会出现这种情况。锁定是默认设置的(overrideModeDefault="Deny"),或者是通过包含 overrideMode="Deny" 或旧有的 allowOverride="false" 的位置标记明确设置的。

这时候只要运行%windir%\system32\inetsrv\appcmd unlock config -section:system.webServer/handlers 其中的handlers是报错的节点名字。


转载地址:https://www.landui.com/FJH1994/p/6292286.html

提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: