Ghost in Subdirectory on Apache2

Context:

I’m attempting to serve Ghost as a sub-directory on my site (example.com/blog) using Apache2 to serve both Ghost and my main web app. I’ve followed most of the tutorials available out there.

I’m using the following setup:
Ghost-CLI version: 1.12.0
Ghost version: 3.0.0
Apache 2.4.29
Ubuntu 18.04

When I set Ghost to serve on the “/” root domain, it works perfectly. I accomplished this through mod_proxy rules on the VirtualHost config file in my apache2/sites-available folder:

ProxyPreserveHost On
ProxyPass / http://127.0.0.1:2368/
ProxyPassReverse / http://127.0.0.1:2368/

Issue:

In an attempt to serve the blog on a sub-directory, I changed configuration information for both Ghost and Apache2. For Apache2 config, it looks like this:

ProxyPreserveHost On
ProxyPass /blog http://127.0.0.1:2368/
ProxyPassReverse /blog http://127.0.0.1:2368/

For Ghost config, I changed the URL to be: “http://example.com/blog

When I hit “/blog” on my site, it just says “Cannot Get /”. Looking at the header information, I see that Express is serving the 404 error page. Since my main app doesn’t use node, I’m pretty sure it’s getting to the Ghost application and then something is failing.

*I’ve tried all combinations of “/” at the end of the configuration lines.

I’m not sure what to try next. Any help would be greatly appreciated!

There’s a bug with certain types of proxying & 3.0, you’ll need to wait for this fix to be released:

1 Like

FYI - the fix landed in 3.0.1.

@m4tch4 I think you need to adjust your proxy rules a little to include the subdirectory…

ProxyPreserveHost On
ProxyPass /blog/ http://127.0.0.1:2368/blog/
ProxyPassReverse /blog/ http://127.0.0.1:2368/blog/

As you were using ProxyPreserveHost and didn’t have separate front-end/admin URLs you wouldn’t have hit the proxy-related bug in 3.0.0.

If you’re using SSL you’ll also need to add this to the config:

RequestHeader set X-Forwarded-Proto https