Optimise your Ghost blog for Raspberry Pi using NGINX
In our last post, we used Supervisor to run Ghost as a service on boot. We are now ready to optimise our Ghost blog using a web server called NGINX.
Being a low resource, high performance and stable HTTP server (and open source), NGINX is an ideal solution to run on our Raspberry Pi Ghost server.
Installing NGINX
Luckily, Raspberry Pi users can install NGINX quickly and easily from the command line as it is available in the Raspbian default repositories. We'll run the following commands to get us up and running:
boo@ghostpi ~ $ sudo apt-get install nginx
boo@ghostpi ~ $ cd /etc/nginx/sites-available/
boo@ghostpi ~ $ sudo nano ghost.conf
This will install NGINX, then we'll change to the install directory and then create a configuration file that will be used to serve our Ghost blog. You'll now need to add the following when Nano has opened, but replacing the {DOMAIN}
with the domain name you own and want to use. In my case, this was simply ghostpi.pro
, so just be sure to set this here:
server {
listen 80;
server_name {DOMAIN};
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368;
}
}
This configuration file will direct our Ghost blog to the relevant server (your domain name) and use the default HTTP port 80, so visitors won't need to add :2368
at the end of the URL.
Again, exit (CTRL+X
) and save (Y
) and then run the following commands to link the configuration file to the right places:
boo@ghostpi ~ $ sudo ln -s /etc/nginx/sites-available/ghost.conf /etc/nginx/sites-enabled/ghost.conf
All that's left is to restart NGINX by running:
boo@ghostpi ~ $ sudo service nginx restart
Read more
If you are interested in gaining a better understanding of how you can maximise the benefits of NGINX, then take a look at Alex Ellis' blog which explores NGINX in greater detail.
Next steps
Now at this point, you may notice that you cannot access your Ghost blog any more. Don't panic! We need to make a few more changes to get this working, and it doesn't take long or much expertise. We'll cover this in the next post.
If you found this guide, as well as any other guides on Ghost Pi helpful, then if you wanted to buy Ghost Pi a coffee to show your support, then that would be greatly appreciated! As this site does not use any form of adverts, all the costs for running and maintaining the blog are done voluntarily so any extra would be fantastic!