This article describes how the site hangs together using a mixture of Node.js, the Ghost blogging platform, nginx and PM2 on Amazon's EC2 cloud hosting.
From the outset, the site was conceived as a collection of demos and prototype applications that could be accessed individually, but that would also have accompanying background article content linking to them.
Since Node.js is our preferred server-side platform, we selected the Ghost blogging engine. A blogging engine was selected over a Content Management System in the hope that it would encourage content population, without getting too hung up on site structure in the early stages.
Ghost is an open source blogging platform that runs on Node.js and uses a SQLite database. It was conceived by one of the Wordpress core team and got off the ground via a kickstarter campaign.
It's easy to self-install, simple to use and there are a range of great themes out there. It uses markdown for article content and handlebars for templating.
It does not currently offer plugins or extensions or about a million other features you'll now find in Wordpress and the like, however it's a joy to use and encourages writing.
We decided to kill two birds with one stone by using a web server that could handle the static content but also proxy traffic to our node back ends. We dismissed Apache because the version installed by our web host does not handle proxying web socket traffic, and we need that for a number of our node demos.
Step up nginx - a high performance web server that can also reverse proxy, and is easy to set up and configure.
Nginx is the front end of the site, and is configured to:
- Proxy the home page and anything beginning with /blog/ to Ghost.
- Detect the path of a number of node applications, reverse proxying web requests and web socket traffic to the appropriate app behind the scenes.
- Detect client subdomains used to serve work-in-progress projects and route accordingly.
- Handle and redirect 404 and 50x server errors.
We can also be secure in the knowledge that if we need to handle anything else, nginx is extremely flexible - for example it can be setup to run PHP.
Node.js and PM2
When running collections of node apps, it can become a challenge just keeping track of them all. PM2 lets you list all your apps (including Ghost) with their port numbers and other details like environment variables in a json file - and will then handle keeping them all running, provide stats and let you start and stop individual apps gracefully.
Making it Live
The site files are managed in git at bitbucket and deployment to EC2 is done manually. With a file-based database like SQLite this is straightforward.
Whilst PM2 is doing a good job of keeping everything running, we need to add monitoring so we know if anything goes wrong.
As we add more content, we also need to give the site some structure - using static pages, adding some navigation and promoting links to categories.