iis服務器上部署node.js解決方法


以下所有內容都是在iis服務器配置成功的基礎上

1. 安裝 node.js,官網下載 node.exe(用express的再安裝express),這步略過。

2. 安裝 iisnode,https://github.com/tjanczuk/iisnode/wiki/iisnode-releases,IIS運行 node.js 的關鍵。

3. 安裝 url-rewrite,http://www.iis.net/downloads/microsoft/url-rewrite

4. 將項目放到指定文件夾下,在這個文件夾下新建一個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="&quot;%programfiles%\nodejs\node.exe&quot;" 
      interceptor="&quot;%programfiles%\iisnode\interceptor.js&quot;" />
    
    -->

  </system.webServer>
</configuration>
  其中<add name="iisnode" path="index.js" verb="*" modules="iisnode" resourceType="Unspecified" 
requireAccess="Script" preCondition="bitness64" />里的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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM