Blogging for free with Ghost blog on Amazon EC2 Instance with your domain
I will walkthrough the steps of blogging for free with Ghost blog on Amazon EC2, well sort of. No, it’s not tumblr.
Ghost is a nodejs based simple blogging platform. It was born in kickstarter.
I really like it. It’s simple yet beautiful.
There are two ways to use ghost, first one is that just go to their site and create an account, after that you will have a blog with a domain <your_name>.ghost.io; second option is to download the source code from the site and host in your instance. Second option is more geeky. So I have gone for it.
Here is a list of things I needed to do in order to setup your own ghost instance:
- Create an aws account, no credit card needed.
- Go to EC2 and create an Ubuntu (I use ubuntu at home so easier for me. However nodejs can run on any platform) instance and run it
- Get the IP address of the instance
- Connect with ssh (Don't forget to download your security group key value pair.)
- Forward your ports for outer connections for example: 80 which is default HTTP port
- Install nodejs
sudo apt-get install node
- Install legacy nodejs whichi will be needed to setup ghost. Some npm packages failed for me to install.
sudo apt-get install node-legacy
- Install node package manager npm
sudo apt-get install npm
- Download latest ghost source code from its site
- scp that zip file to your instance from your computer. Or alternatively you can do a wget in the ssh-ed instance
-
wget https://ghost.org/zip/ghost-0.4.2.zip
- Install unzip and unzip the zip file
sudo apt-get install unzip
unzip ghost-0.4.2.zip
- cd to ghost unzipped directory where core folder is. Run:
npm install --production
-
npm start
- Stop the server - Ctrl + C
- Now there are two ways to redirect requests to ghost. First of all, make sure you opened your port 80 which is default port for the HTTP requests. If you want to connect your blog via <IP_ADDRESS> not via <IP_ADDRESS>:8080 (ugh ugly), you need to do this. You can do this operations under aws console on security groups -> Inbounds
- After forwarding port 80, you need to say the instance that if a request comes to 80, ghost should handle it. This part is tricky.
- Install nginx which is a lightweight server to handle requests.
-
sudo apt-get install nginx
- Do the nginx magic - Many thanks for this pal
- Go to <IP_ADDRESS>:80/ or <IP_ADDRESS>. They are basically same. Because default HTTP request is from port 80.
- My additional steps
- Nginx default page started to show up every time I go to my instance's address even though it must route requests from port 80 to localhost:2368/ (my ghost instance running there on the machine).
- To disable this, I did an ugly hack.
-
sudo nano /etc/nginx/sites-available/default
- I changed first server to listen port 81 instead of port 80.
-
sudo service nginx restart
Steps to connect this instance to your domain
- Buy a domain from godaddy.com or anywhere you want
- Create a totally free cloudflare.com account - there are other alternatives. I found this the easiest.
- Put your domain in cloudflare and let it scan your nameservers
- After a while it will give you nameservers to assign to domain.
- Go to godaddy domain control panel or whatever provider you have and change the default nameservers to given cloudflare ones
- It will take some to pick it up. After making it active, go to cloudflare DNS settings
- Add a new A attribute with the IP of your amazon EC2 instance. It means that whenever you type your domain address, it will be responsed through your server which is running on EC2 instance in the address of <IP_ADDRESS>:80/ That's why we put a lot of effort to run the ghost on port 80. It's impossible to assign other ports on domains as far as I know. At least for http requests.
- After propagation which may take quite some time, go to your domain and check your awesome ghost blog.
- Congrats you have a Ghost blog on Amazon EC2!
- For example check mine: websitem.co
[OPTIONAL] To change ghost default running port:
- cd to your ghost directory
- there is a file called config.example.js, create a copy and name it as config.js
-
cp config.example.js config.js
-
nano config.js
- At line ~40, there is "port: '2368'", change it to "port: '8080'"