Jekyll and IIS Web Configuration in Windows Azure

In a previous post, “Deploying Jekyll on Windows Azure”, I detailed how to get a Jekyll based site on to Windows Azure with relative ease. During that time, the team has done several deployments to our cloud provider. With those deployments, we realized we needed to commit more work into the site’s web.config to get the solution we really wanted. We are happy with our current outcome, but understand there may be edge cases we still haven’t hit, and hope to come back and update this post when necessary.

HTTP Errors

It is rare to have server-side errors on a staticly generated site, and the most common one will be 404. Right now, we are just leaning on the httpErrors element under system.webServer to redirect to a default error page.

HTML5 Static Content

HTML5 is a part of our site building strategy, but the initial IIS configuration is not supportive of our strategy. With some help from Mads Kristensen, we modified our web.config with the staticContent element.

Rewrite Rules

Rewrite rules are the most critical part of our Jekyll/IIS configuration and account for much of the necessary behavior we are looking for. Not all the rewrite rules you will see below are Jekyll specific. Rewrite rules are normally located under system.webServer/rewrite.

Redirecting to HTTPS

All of our sites will run on HTTPS by default. To enforce the secure behavior we used an inbound rule.

<rulename="Redirect to HTTPS"stopProcessing="true"><matchurl="(.*)"/><conditions><addinput="{REMOTE_PORT}"pattern=".*"/><addinput="{HTTPS}"pattern="^OFF$"/></conditions><actiontype="Redirect"url="https://{HTTP_HOST}/{R:1}"redirectType="Permanent"/></rule>

Support Non-Trailing Slash Urls

Trailing slashes are no longer a default in Jekyll 3. If you find yourself on a previous version those slashes can be annoying. Additionally, you may have someone accidentally add a trailing slash, because old habits die hard. Generally, this isn’t a behavior we liked, so we needed to create a rule that supported access to pages without the trailing slash.

By default, Windows Azure wants to gzip your static content. You cannot apply an outbound rule on content that has been compressed. If your Jekyll site begins to fail after adding this rule, you probably forgot the rewriteBeforeCache attribute.

The Complete Configuration

Putting all of these configuration settings together, we get the following web.config: