When you use iisnode to host the Node.js blogging software Ghost on your IIS web server, and you set up an SSL certificate for your Ghost website, you may run into too many redirect issues when changing Ghost's config.js file. This happend to me yesterday, and here is the solution.

IIS acts as a reverse proxy for Node.js

The most important thing I forgot is that IIS acts as a reverse proxy for Node.js web applications when you install iisnode. I had my SSL certificate set up in IIS, put my HTTP to HTTP redirect in place and updated my Ghost url: and server: production environment config in config.js, I changed http to https.

Assuming all was correct and in place, I recycled my application pool, which is necessary for Ghost config changes, and refreshed my browser. Only to find an error HTTP 310 Too many redirects... Darn!

Here is how to resolve the "too many redirects" error in Ghost on IIS

TL;DR, read this blog post to find the answer.

Undoing my config.js changes, the problem went away. Googling on the "HTTP 310 Too many redirects" error, I found the above mentioned blog post, and all pieces came together falling into place:

IIS acts as a reverse proxy through iisnode for the Node.js web applications. Node.js runs its own HTTP web server on localhost. Doh! How could I forget... Anyway, create an iisnode.yml file in your web root (or edit the file if it exists), and add (or change):

enableXFF: true

However:

The enableXFF setting controls whether iisnode adds or modifies the X-Forwarded-For request HTTP header with the IP address of the remote host. After recycling your application pool, Ghost runs on HTTPS / port 443 in Node.js without problems. You can find more iisnode configuration settings in iisnode's web.config

This means you don't have to create an iisnode.yml file if it doesn't exist. Make your change in the web.config file:

<iisnode
  node_env="%node_env%"
  loggingEnabled="false"
  debuggingEnabled="false"
  devErrorsEnabled="false"
  nodeProcessCommandLine=""c:\path\to\node.exe""
  enableXFF="true"
/>
Donate a cup of coffee
Donate a cup of coffee

Thank you very much! <3 ❤️

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *