Install Node on IIS
- Download IIS URL Rewrite (rewrite_amd64_de-DE.msi)
- Download nodeiis (iisnode-full-v0.2.21-x64.msi)
Configure web.config
So fare we have installed all required modules. Next we have to configure the web.config to process all requests by the iisnode handler.
<configuration><system.webServer><iisnodelogDirectory="c:\inetpub\wwwroot\my-website\_data\iisnode"devErrorsEnabled="false"flushResponse="true"enableXFF="true" /><httpErrors existingResponse="PassThrough" /><handlers><add name="iisnode" path="main.js" verb="*" modules="iisnode" /></handlers><rewrite><rules><rule name="NodeApp"><match url=".*" /><action type="Rewrite" url="main.js" /></rule></rules></rewrite></system.webServer></configuration>
Important settings
I highly recommend you to configure the following settings.
httpErrors existingResponse="PassThrough"
This will prevent, that IIS intercepts any response you send from your Node app.
By default IIS will replace any response with 4XX and 5XX status codes.devErrorsEnabled="false"
This will prevent from show sensitive data to the end user which is very important! Only practical in development environment.logDirectory
WhiledevErrorsEnabledshould strictly be disabled/falsein production.logDirectorywill log all warnings and errors.flushResponse="true"
This will send your response in chunks (not buffered) which means your page will render faster.enableXFF="true"
This setting is required if you need the client/remote IP address. (req.headers['x-forwarded-for'])
web.config iisnode default values
https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config<iisnodenode_env="%node_env%"nodeProcessCountPerApplication="1"maxConcurrentRequestsPerProcess="1024"maxNamedPipeConnectionRetry="100"namedPipeConnectionRetryDelay="250"maxNamedPipeConnectionPoolSize="512"maxNamedPipePooledConnectionAge="30000"asyncCompletionThreadCount="0"initialRequestBufferSize="4096"maxRequestBufferSize="65536"watchedFiles="*.js;iisnode.yml"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" />