Subdirectory install for your Ghost site hosted on Magic Pages

Jannis
By Jannis, Founder
Last updated: 18 October 2024

If you want to run your Ghost blog in a subdirectory (e.g., yourdomain.com/blog) while hosting the rest of your website elsewhere, you can achieve this with Magic Pages. This setup primarily involves configuring a reverse proxy on your end – so, there is some technical work involved for you. Here is how you can do it:

1. Set Up Your Ghost Blog on Magic Pages

First, create your Ghost website on Magic Pages as you normally would. You can sign up here. For this tutorial, let's say your blog is using the Magic Pages subdomain yourblog.mymagic.page.

2. Configure Your Reverse Proxy

The main technical work happens on your side. You'll need to set up a reverse proxy on your main domain to forward requests from the /blog subdirectory to your Magic Pages Ghost instance. Here's an example configuration for Nginx:

server {
    server_name yourdomain.com;

    # Your existing website configuration goes here

    location /blog {
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host yourblog.mymagic.page;

        proxy_pass https://yourblog.mymagic.page;
    }

    # SSL configuration
    listen 443 ssl;
    ssl_certificate /path/to/your/ssl/certificate.pem;
    ssl_certificate_key /path/to/your/ssl/certificate_key.pem;
}

This configuration does the following:

  • Forwards requests from yourdomain.com/blog to your Magic Pages Ghost instance hosted at yourblog.mymagic.page.
  • Sets the necessary headers for proper forwarding – without these headers, things won't work as expected.
  • Assumes you have SSL set up for your main domain (certbot is your friend).

3. Let Magic Pages Know About the Subdirectory

So far, there is no automated self-serve way of activating the subdirectory domain. Once you have done the above configuration, please reach out to help@magicpages.co (or using the live chat).

Important Notes

This setup requires you to have control over your main domain's web server configuration. Due to the technical nature of this, Magic Pages only recommends subdirectory installation if you or somebody in your team can handle the technical overhead.

The example above is using Nginx as a web server. However, any web server or reverse proxy should be able to achieve the same result. The important principle is that you forward all requests made to your subdirectory, including their paths, to your Magic Pages site.

Required Headers

Regardless of the reverse proxy you're using, the following headers need to be set:

X-Forwarded-Proto: [should be https]
X-Forwarded-Host: [e.g. yourdomain.com])
X-Real-IP: [client IP address]
X-Forwarded-For: [client IP address]
Host: [e.g. yourblog.mymagic.page]

These headers ensure that:

  • The correct protocol (http or https) is communicated to the Ghost instance ( X-Forwarded-Proto).
  • The original host (your domain) is preserved for Ghost to generate correct URLs (X-Forwarded-Host).
  • The real IP address of the client is passed through to the Ghost instance (X-Real-IP).
  • The original client IP is preserved if there are multiple proxy hops (X-Forwarded-For).
  • The request is routed to the correct Magic Pages Ghost instance (Host).

In your reverse proxy configuration, you'll need to set these headers dynamically. The exact syntax will depend on your reverse proxy software.

For example, in Nginx, you would use variables like $scheme$host, and $remote_addr as shown in the configuration example above.

Still have questions?

I am here to help and want to make sure you get the most out of your Ghost site. Reach out directly and I'll get back to you as soon as possible.

Customer Showcase

Websites powered by Magic Pages

See what real publishers have built with Ghost CMS and Magic Pages hosting.

Start Your 14-Day Free Trial

No credit card required • Set up in minutes