Deploying Node App in IIS

parthsw picture parthsw · Sep 7, 2017 · Viewed 8.4k times · Source

I'm trying to deploy node app on windows server 2012 R2 and facing issue while doing the same.

Server: Windows Server 2012 R2

1) I've installed IIS node from https://github.com/tjanczuk/iisnode/wiki/iisnode-releases [iisnode for iis 7/8(x64)]

2) Installed URL Rewrite module from https://www.iis.net/downloads/microsoft/url-rewrite

3) Placed all node app files at a certain location.

4) From that project directory, issued npm install to install required packages.

server.js

web.config

<configuration>
   <system.webServer>

     <!-- indicates that the server.js file is a node.js application 
     to be handled by the iisnode module -->

     <handlers>
       <add name="iisnode" path="server.js" verb="*" modules="iisnode" />
     </handlers>

     <!-- use URL rewriting to redirect the entire branch of the URL namespace
     to server.js node.js application; for example, the following URLs will 
     all be handled by server.js:
     
         
     -->

     <rewrite>
       <rules>
         <rule name="rewriteRule">
           <match url="/*" />
           <action type="Rewrite" url="server.js" />
         </rule>
       </rules>
     </rewrite>

     <!-- exclude node_modules directory and subdirectories from serving
     by IIS since these are implementation details of node.js applications -->
     
     <security>
       <requestFiltering>
         <hiddenSegments>
           <add segment="node_modules" />
         </hiddenSegments>
       </requestFiltering>
     </security>    
     
   </system.webServer>
 </configuration>

Then using IIS, I've created one website who refers to this particular project folder. Provided port number as 9025 while creating website. When I'm trying to access this URL from other machine i.e. http://servername:9025/ I'm getting the below error: enter image description here

I even tried using process.env.PORT instead of directly using 9025. At that time I'm getting 404 not found.

Please let me know what am I doing wrong?

Answer

Darshan Dave picture Darshan Dave · Jan 10, 2020

I found one blog and I personally feel that the mentioned way on the blog is much better then IISNode. Kindly please go through the below blog.

Hosting a Node.js application on Windows with IIS as reverse proxy

I know it too late to answer this question but no one has answered yet so I have answered. I hope it will help others.