Skip to content

Instantly share code, notes, and snippets.

@pbaio
Last active February 22, 2024 21:10
Show Gist options
  • Star 24 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save pbaio/f63918181d8d7f8ee1d2 to your computer and use it in GitHub Desktop.
Save pbaio/f63918181d8d7f8ee1d2 to your computer and use it in GitHub Desktop.
IISNode Web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<!--
All appSettings are made available to your Node.js app via environment variables
You can access them in your app through the process.env object.
process.env.<key>
-->
<!-- Unconmment the below appSetting if you'd like to use a Virtual Directory -->
<!-- <add key="virtualDirPath" value="" /> -->
</appSettings>
<system.webServer>
<!-- Remove the modules element if running on IIS 8.5-->
<modules runAllManagedModulesForAllRequests="false"/>
<httpErrors existingReponse="PassThrough"></httpErrors>
<iisnode node_env="%node_env%"
nodeProcessCountPerApplication="1"
maxConcurrentRequestsPerProcess="1024"
maxNamedPipeConnectionRetry="100"
namedPipeConnectionRetryDelay="250"
maxNamedPipeConnectionPoolSize="512"
maxNamedPipePooledConnectionAge="30000"
asyncCompletionThreadCount="0"
initialRequestBufferSize="4096"
maxRequestBufferSize="65536"
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"
promoteServerVars=""
configOverrides="iisnode.yml"
watchedFiles="web.config;*.js"
nodeProcessCommandLine="C:\Program Files\nodejs\node.exe"/>
<!--
Before the handlers element can work on IIS 8.5
follow steps listed here https://github.com/tjanczuk/iisnode/issues/52
-->
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
<!-- Uncomment below handler if using Socket.io -->
<!--<add name="iisnode-socketio" path="server.js" verb="*" modules="iisnode" />-->
</handlers>
<rewrite>
<rules>
<!-- Don't interfere with requests for node-inspector debugging -->
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^server.js\/debug[\/]?"/>
</rule>
<!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
<rule name="StaticContent" patternSyntax="Wildcard">
<action type="Rewrite" url="public/{R:0}" logRewrittenUrl="true"/>
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
</conditions>
<match url="*.*"/>
</rule>
<!-- All other URLs are mapped to the Node.js application entry point -->
<rule name="DynamicContent">
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
<rule name="SocketIO" patternSyntax="ECMAScript">
<match url="socket.io.+"/>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
<directoryBrowse enabled="false"/>
</system.webServer>
</configuration>
@moorthi07
Copy link

IISNode lists the source code of the file if your server.js is in different folder (like server/server.js). Even if you put a server.js in the root with require ('\server\server.js') - it doesn't work. Any idea?

@pbaio
Copy link
Author

pbaio commented Feb 25, 2016

Sounds like you need to install the URL ReWrite Module for IIS

@g-aaroncruz
Copy link

g-aaroncruz commented Jun 13, 2016

When my HTML files reference a CSS or Image file, via a relative path, the application attempts to send a request to "localhost/myapp/css/navbar.css," which leads to a 404 error. Have you ever seen this issue?

@aeciolevy
Copy link

Guys I could not make static content work with iisnode.

This is my web.config

<configuration>
  <system.webServer>


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

    <rewrite>
      <rules>
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^app.js\/debug[\/]?" />
        </rule>

        <rule name="LogFile" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="iisnode"/>
        </rule>

        <rule name="StaticContent" patternSyntax="Wildcard">
                    <action type="Rewrite" url="public/{R:0}" logRewrittenUrl="true"/>
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true"/>
                    </conditions>
                    <match url="*.*"/>
                </rule>

        <rule name="DynamicContent">
          <conditions>
            <add input="{{REQUEST_FILENAME}}" matchType="IsFile" negate="True" />
          </conditions>
          <action type="Rewrite" url="server.js" />
        </rule>

      </rules>

    </rewrite>

  </system.webServer>
</configuration>

This is the source that I am using to access the scripts:

<script type="text/javascript" src="scripts/app.js"></script>

My server configuration:

app.use(express.static(path.join(virtualDirPath, "public")));

screen shot 2017-05-22 at 11 34 08 am

@megancooper
Copy link

@pbaio Do you know why 404 errors with POST requests could be occuring using this template? The POST requests are handled in my server.js file

@ves-krd
Copy link

ves-krd commented May 21, 2018

@pbaio I keep getting 404 errors on transport-polling request from socketio, any ideas?

@gangwar1
Copy link

Hi,
I am using the same IISNODE for deploying the Node Express application over iis by using iisnode module.
we are facing one isssue, if any rquest take log time iisnode will return the error response in max 2 min it not wait to complete my request,

Is there any way to increase the rquest timeout on iisnode? if any one have any idea please help me.

@SulaimanGit
Copy link

Hi, its working fine on http in IIS by setting up as instructed. On http it shows all status returned through Express Js.
However, when hosting it on https with ssl, it only returns 200 status and all other statuses 400, 300 etc are sent as 500 with default 500 message.
Any help would be appreciated

@mossy1k
Copy link

mossy1k commented Aug 5, 2021

Please Help me resolve this issue

iisnode encountered an error when processing the request.

HRESULT: 0x6d
HTTP status: 500
HTTP subStatus: 1013
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 last 64k of the output generated by the node.exe process to stderr is shown below:

[x1B][5m[x1B][31mFailed to connect to http://sql5083.site4now.net:1433 - getaddrinfo ENOTFOUND http://sql5083.site4now.net[x1B][39m[x4B][24m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment