Hello, my name is John Flynn. I am a tech enthusiast, maker and tinkerer. This is my blog where I write about stuff.

tags

Serving Ghost with Apache

Ghost is a great blogging platform built with node.js. It is what I use to run this blog. Most of the instructions online deal with using NGINX to proxy requests to and from the running node instance. I needed to use Apache, since the server I installed on already has Apache. This guide will show you how to set up proxy pass on Apache.

Getting Started

You should already have these prerequisites installed:

  • Linux Server
  • Apache 2
  • NodeJS and Ghost

To start we need to install the proxy pass Apache module:

sudo apt-get install libapache2-mod-proxy-html libxml2-dev

We then need to install enable the modules:

sudo a2enmod proxy proxy_ajp proxy_http rewrite deflate headers proxy_balancer proxy_connect proxy_html

Then restart Apache:

sudo service apache2 restart

After restarting Apache, I got the following error on Ubuntu 13.10:

I18n support in mod_proxy_html requires mod_xml2enc. Without it, non-ASCII characters in proxied pages are likely to display incorrectly.

After doing a quick Google search, I found this solution in the Ubuntu forums, http://askubuntu.com/questions/368515/upgraded-to-ubuntu-13-10-apache-not-able-to-start:

sudo apt-get install apache2-prefork-dev
mkdir ~/modbuild/ && cd ~/modbuild/
wget http://apache.webthing.com/svn/apache/filters/mod_xml2enc.c
wget http://apache.webthing.com/svn/apache/filters/mod_xml2enc.h
apxs2 -aic -I /usr/include/libxml2 ./mod_xml2enc.c
cd ~
rm -rfd ~/modbuild/
sudo service apache2 restart

Apache came up without errors after compiling and installing the module from source.

Time to change Apache’s configuration

After getting the correct modules installed, it is time to enable proxy pass for your website. I use virtualhosts on my server, so I only enabled proxy pass for the virtualhost that serves this site.

Edit your configuration file for your virtualhost under:

/etc/apache2/sites-available

You will need to add these lines:

ProxyPreserveHost On

# Servers to proxy the connection, or;
# List of application servers:
# Usage:
# ProxyPass / http://[IP Addr.]:[port]/
# ProxyPassReverse / http://[IP Addr.]:[port]/
# Example: 
ProxyPass / http://0.0.0.0:2368/
ProxyPassReverse / http://0.0.0.0:2368/

The port 2368 is what Ghost’s built in server listens on. This is telling Apache to take any http requests for this site and forward them to our Ghost server.

You can now reload Apache’s configuration:

sudo service apache2 reload

With luck, you will now be able to browse to your site and Ghost will open up.

comments powered by Disqus