Self hosting Ghost blog on Windows 2008

Ghost is Node JS application built on Wordpress concept but more light weight. I have a Windows 2008 server running IIS service and I want to run Ghost on my Windows server.

Ghost Installation

Basically, the instruction for installing Ghost can be found on its GitHub page. At the present time, Node JS page provides Node 4 as stable version and Node 6 as preview version. I have tried the installation with Node 6 but it failed for it needs to compile sqlite3 on Windows but my server does not have VC compiler installed.

With Node 4, the installation was smooth (it used pre-compiled binary of sqlite3). Version of Ghost I was using was 0.8.0. Following the Ghost installation guide and it should just work.

Setting IIS as a Reverse Proxy

Setting IIS Site for blog

Ghost runs its own web server with NodeJS and I do not want to publish Ghost port directly. Since I have IIS installed, I can transform IIS into a Reverse Proxy with ARR1 add-on. I also want to publish my Ghost blog on domain blog.ruxoz.net. What I have to do first is to create a new site for this blog under Sites folder in IIS Manager.

Add a new site

Physical path in the setting can be anything since we are going to forward request to Ghost server, this value will be ignored (but alas, you have to input something, otherwise you cannot click OK button :s )

The name of Site name does not matter as well. Just anything that is not existed in IIS yet. What matter is Host name, which IIS uses for routing requests when blog.ruxoz.net is being accessed.

Forward request to Ghost

Click on the newly created site. Under IIS section, you should see URL Rewrite. This is for forwarding request of this site to other server. Double-click on URL Rewrite and add a new rule.

IIS section

A rule dialog should be poped up. The rule we need is Reverse Proxy, double-click on it to set up one. This step will invoke ARR installation if your IIS has never installed ARR before. Just following its ARR installation instruction, and resume adding this Reverse Proxy rule.

Adding a new rule

Enter Ghost server IP and port into the dialog. Default setting of Ghost server publishes on port 2368. So simply input 127.0.0.1:2368 into Inbound Rules and click OK.

Reverse Proxy setting

Change Ghost Server Port

In Ghost directory, there is a config file named config.js 2. Default server setting is under server node, as shown in the picture below.

Set Ghost Server URL

Another important setting is url key, which normally is set to http://my-ghost-blog.com as shown on the above picture. This value must be set to URL that will be accessed from outside, in this case I set to http://blog.ruxoz.net.

Other Settings

Email Setting

This is also a mandatory but Ghost can work fine without this setting. Full email setting instruction can be found in http://support.ghost.org/mail. For me, I use my Gmail SMTP server, so I simply followed the Gmail setting instruction in the page.

To use Gmail SMTP, you have to generate Google's "App Password" in Google's Account manager. Then, use App Password in the email setting.

e-mail setting

Allow Image Upload

The setting to allow image uploading is fileStorage. Strangely, its description in Ghost configuration page2 states like it is enabled by default, but I find that it does not work if not specified. So I just add this flag into the config file to enable image upload.

Image Upload setting

Database

Ghost uses SQLite database by default. Refer to Ghost configuration page2 for changing database. For me, I create a database and a credential in MySql, then just replace it in config.js file.

Database setting

Auto Start Ghost Server

I use Windows Task Scheduler to turn on Ghost server when Windows is started. Open Task Scheduler and, under Action menu, add a Basic Task.

Here, a few information you need to enter.

  • Name: Name of Task, can be anything.
  • Trigger: Use When the computer starts
  • Action: Use Start a program
    • Program/Script: Find npm.cmd in C:\Program Files\nodejs.
    • Add arguments: Use start --production
    • Start in: Enter directory name of our Ghost Server.
  • Finish: Tick Open the Properties dialog for this task when I click Finish

Then click Finish.

A few more settings are needed to be done in Task Properties dialog.

  • General tab, under Security options: Use Run whether user is logged on or not. Also tick Do not store password.
  • Settings tab: Untick Stop the task if it runs longer than

Then click OK.

You can try to manually start the task by right-clicking at the task name and select Run.

Administration Setup

Once the site is started, you should setup a blog by goto path /ghost/, such as http://blog.ruxoz.net/ghost/.

Ghost welcome page

Following the provided instruction (i.e. Enter email/password, blog title, etc.) then your blog are ready!

Add Prism (Optional)

Prism is code block prettifier for Javascript. If your blog is having some code blocks and you want to colorize them, just setting our blog with Prism. There is Prism cached on CloudFlare, your can just directly use them.

Go to Code Injection in Ghost settings page. Push following code in Blog Header.

<link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/themes/prism.css" rel="stylesheet" />  

Depend on what kind of code you want to highlight, you can load one or more prism*.min.js. Just put it in Blog Post like following example.

<script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/prism.min.js"></script>  
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/components/prism-fsharp.min.js"></script>  
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/components/prism-json.min.js"></script>  
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/components/prism-bash.min.js"></script>  

References

  1. Application Request Routing -- more detail on (http://www.iis.net/downloads/microsoft/application-request-routing) ?

  2. Ghost configuration (http://support.ghost.org/config/) ?