Saturday 10 May 2014

How To Proxy Ghost Through Apache – For Security and Multi Blog Setup

Setting up Ghost to run through Apache is a popular option for two main reasons: running Ghost from a non-root user, and giving yourself the flexibility of running multiple Ghost blogs on the same server. Ghost by default runs on port 2368, so Ghost does not need root level permissions. Whenever running Ghost in a production environment, it is strongly recommended to start Ghost with a user that has limited privileges.


With the following snippet added into your Apache configuration file, you can proxy requests for your domain name through Apache to the port Ghost is running on. By default, on CentOS, the main Apache configuration file can be found in /etc/httpd/conf.d. On Ubuntu it can be found in/etc/apache/. There are many ways to add the following configuration into Apache and which is better is beyond the scope of this article. For an explanation of your options, checkout this ServerFualt question. Whichever option you pick, place the following configuration in the file, changing ServerName and ServerAlias to your specific configuration.
NameVirtualHost *:80
<VirtualHost *:80>
     ServerName your-url.com
     ServerAlias www.your-url.com
     ProxyRequests off
     ProxyPass / http://127.0.0.1:2368/
     ProxyPassReverse / http:/127.0.0.1:2368/
</VirtualHost>
Now restart Apache. If you are running CentOS, run sudo service httpd restart and if you are on ubuntu run sudo service apache2 restart.
Very similar to proxying all requests to a single Ghost blog, Apache can be used to filter requests for multiple Ghost blogs with the Apache ProxyPass directive. This little snippet can be repeated for any number of Ghost blogs you want to run on the same server. For every Ghost blog you will need to have a separate domain name that resolves to the IP address of the server.
Again, place this in your preferred Apache configuration file replacing the ServerName and ServerAlias URL’s. Also note every Ghost blog will have to be configured to run on a different port, which can be configured in Ghost’s config.js file. After restarting Apache each domain name will resolve to a specific instance of Ghost.
NameVirtualHost *:80
<VirtualHost *:80>
     ServerName your-url.com
     ServerAlias www.your-url.com
     ProxyRequests off
     ProxyPass / http://127.0.0.1:2368/
     ProxyPassReverse / http:/127.0.0.1:2368/
</VirtualHost>
<VirtualHost *:80>
     ServerName your-second-url.com
     ServerAlias www.your-second-url.com
     ProxyRequests off
     ProxyPass / http://127.0.0.1:8080/
     ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>

No comments:

Post a Comment