Running Ghost behind Apache Reverse Proxy
Von Carsten
After migrating to Ghost a couple of days ago, I wanted to hide the application behind my Apache HTTP Server. Because I’m running my blog on a subdomain I already had a VirtualHost configured, so the question was how to set up mod_proxy to forward all requests to Ghost.
Here’s my apache configuration for the virtual host on which my blog is hosted on my server:
<Virtualhost *:80>
ServerName blog.myserver.tld
ServerAlias www.myserver.tld blog.myserver.tld
ServerAdmin webmaster@localhost
RewriteEngine On
RewriteOptions Inherit
# rewrite jekyll URLs to Ghost URLs
RewriteRule ^/d{4}-d{2}-d{2}-(.+?)/?$ $1 [R]
RewriteRule ^/d{4}/d{2}/d{2}/(.+?)/?$ $1 [R]
# previous feed address to ghost feed
RewriteRule ^/atom.xml$ /rss [R]
<ifmodule mod_proxy.c>
ProxyVia On
ProxyRequests Off
ProxyPass / http://www.kopis.de:2368/
ProxyPassReverse / http://www.kopis.de:2368/
ProxyPreserveHost on
<proxy *>
AllowOverride All
Order allow,deny
allow from all
</proxy>
</ifmodule>
</Virtualhost>
You can also see my RewriteRules here that help me keep old URLs from my Jekyll blog and not loose any search results due to broken URLs. That was quite important to me, because I think you shouldn’t break URLs when migrating your underlying software. Unfortunately, Ghost does not yet provide a mechanism to customize the URLs, so I had to go with this redirects as suggested by W3C.
Additionally, with real redirects I can instruct Disqus to crawl my website again and auto-fix all comments, which are tied to URLs in their system. No more URL mapping spreadsheets to edit! 🙂