Reverse proxy using apache and cloudflare

So Im using apache to reverse proxy the ghost domain. I was hoping to have my ghost site live on https:///www.example.com/blog/

here is what I have in my ssl.conf

SSLProxyEngine On
<Location /blog/>
    ProxyPass https://the-acme-blog.ghost.io
    ProxyPassReverse https://the-acme-blog.ghost.io
</Location>

Seems apache is doing its job but then I get a Domain error
Failed to resolve DNS path for this host with https://error.ghost.org/ in url bar when i try navigating to https:///www.example.com/blog/

Im using cloudflare for the entire domain if that makes a difference.

Any help or suggestions would be appreciated.

You should be proxying localhost:port, and setup your Ghost config for the FQDN, plus routes for /blog.

1 Like

I see, so I’ll need to use the open source version of ghost CMS correct?

Im using Ghost pro and from what I understand this is something that will cost me $300 a month? (200 for business and 100 for the subdirectory add-on)?

Ghost Pro expects to serve your domain with the name that you have pointing at it, with a CNAME and A record. You can’t set it up to serve your site at http://yoursite.com if you don’t have the yoursite.com DNS record pointed at it along with a www. A record that’s a CNAME for your ghost.io domain. [If you’re setting up with cloudflare, I’ve had best success with the proxying turned off while I got the domain through the Ghost verification process.]

If you want to stay with Ghost Pro, you could have a Cloudflare proxy in front of your Ghost Pro site and accomplish this with a worker that does some rewriting. [This could probably also be done with Apache, but I think you’re going to get better results from Cloudflare, especially if you’re already proxying with them.

So what you can do is set up Ghost Pro with a blog.yoursite.com record, and then use a Cloudflare worker to respond to requests for yoursite.com/blog/* with the response from blog.yoursite.com/*. Some rewriting of the URLs within the response body will probably also be necessary

3 Likes

I like this but there is an entire site that lives on yoursite.com domain so when I try to add the CNAME www to the ghost subdomain cloudflare gives me an error that one exists. Im basically trying to replace the WP blog that lives in that subdirectory on my server.The routing with ghost pro looks good, if I replace the ghost subdomain with example.com/blog/ that would suffice.

Appreciate your suggestions

The root domain record is not required. If you have a cname from blog.yourdomain.com to the ghost.io subdomain, you should be sble to activate.

1 Like

so close!

i have the blog on example.com/blog/ working with CF workers.

The links generated for the posts ( i had imported posts earlier) … dont have the /blog/ so they 404 … the routes.yaml

I tried

## routes.yaml

routes:

collections:
  /:
    permalink: /blog/{slug}/
    template: index

taxonomies:
  tag: /blog/tag/{slug}/
  author: /blog/author/{slug}/

and chatgpt 4 suggested

routes:

collections:
  /blog/:
    permalink: /blog/{slug}/
    template: index

taxonomies:
  tag: /blog/tag/{slug}/
  author: /blog/author/{slug}/

and the worker ( also thanks to chatgpt)

addEventListener('fetch', event => {
  event.respondWith(handleRequest(event.request))
})

async function handleRequest(request) {
  const url = new URL(request.url)
  if (url.pathname.startsWith('/blog/')) {
    const blogURL = 'https://blog.example.com' + url.pathname.replace('/blog', '')
    const response = await fetch(blogURL, request)

    // Check if the content is HTML
    const contentType = response.headers.get('content-type')
    if (contentType && contentType.includes('text/html')) {
      let body = await response.text()

      // Rewrite links in the HTML content
      body = body.replace(/https:\/\/blog\.example\.com\//g, 'https://www.example.com/blog/')

      return new Response(body, {
        status: response.status,
        statusText: response.statusText,
        headers: response.headers
      })
    }

    return response
  }

  return fetch(request)
}

whats interesting is the “about” url works … it has the /blog/ in it.

Any ideas? :face_with_peeking_eye:

Edit My mistake and this works! I re-read the docs and I probably had spacing issues with the YAML file.

The most important thing to know when working with YAML is that it uses indentation to denote structure. That means the only type of nesting which works is 2 spaces.

The most common reason for YAML files not working is when you accidentally use the wrong type or quantity of spacing for indentation. So keep a close eye on that!

Thank you very much @Cathy_Sarisky