# Reverse proxy using apache and cloudflare

**URL:** <https://forum.ghost.org/t/reverse-proxy-using-apache-and-cloudflare/41254>\
**Category:** Developer help\
**Created:** [September 17, 2023, 1:37am UTC](https://forum.ghost.org/t/reverse-proxy-using-apache-and-cloudflare/41254 "2023-09-17T01:37:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fly\_high](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/fly_high/32/25754_2.png) [@fly\_high](https://forum.ghost.org/u/fly_high)\
**Post date:** [September 17, 2023, 1:37am UTC](https://forum.ghost.org/t/reverse-proxy-using-apache-and-cloudflare/41254/1 "2023-09-17T01:37:13Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![mjw](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/mjw/32/30781_2.png) [@mjw](https://forum.ghost.org/u/mjw)\
**Post date:** [September 17, 2023, 9:09am UTC](https://forum.ghost.org/t/reverse-proxy-using-apache-and-cloudflare/41254/2 "2023-09-17T09:09:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![fly\_high](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/fly_high/32/25754_2.png) [@fly\_high](https://forum.ghost.org/u/fly_high)\
**Post date:** [September 17, 2023, 1:42pm UTC](https://forum.ghost.org/t/reverse-proxy-using-apache-and-cloudflare/41254/3 "2023-09-17T13:42:31Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![Cathy\_Sarisky](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/cathy_sarisky/32/25750_2.png) [@Cathy\_Sarisky](https://forum.ghost.org/u/Cathy_Sarisky)\
**Post date:** [September 17, 2023, 3:50pm UTC](https://forum.ghost.org/t/reverse-proxy-using-apache-and-cloudflare/41254/4 "2023-09-17T15:50:04Z")

</div>

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](http://yoursite.com) if you don’t have the [yoursite.com](http://yoursite.com) DNS record pointed at it along with a www. A record that’s a CNAME for your [ghost.io](http://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](http://blog.yoursite.com) record, and then use a Cloudflare worker to respond to requests for [yoursite.com/blog/\*](http://yoursite.com/blog/*) with the response from [blog.yoursite.com/\*](http://blog.yoursite.com/*). Some rewriting of the URLs within the response body will probably also be necessary

---

<div class="post-metadata">

**Author:** ![fly\_high](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/fly_high/32/25754_2.png) [@fly\_high](https://forum.ghost.org/u/fly_high)\
**Post date:** [September 18, 2023, 1:02am UTC](https://forum.ghost.org/t/reverse-proxy-using-apache-and-cloudflare/41254/5 "2023-09-18T01:02:01Z")

</div>

I like this but there is an entire site that lives on [yoursite.com](http://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/](http://example.com/blog/) that would suffice.

Appreciate your suggestions

---

<div class="post-metadata">

**Author:** ![Cathy\_Sarisky](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/cathy_sarisky/32/25750_2.png) [@Cathy\_Sarisky](https://forum.ghost.org/u/Cathy_Sarisky)\
**Post date:** [September 18, 2023, 1:10am UTC](https://forum.ghost.org/t/reverse-proxy-using-apache-and-cloudflare/41254/6 "2023-09-18T01:10:04Z")

</div>

The root domain record is not required. If you have a cname from [blog.yourdomain.com](http://blog.yourdomain.com) to the [ghost.io](http://ghost.io) subdomain, you should be sble to activate.

---

<div class="post-metadata">

**Author:** ![fly\_high](https://sea1.discourse-cdn.com/flex015/user_avatar/forum.ghost.org/fly_high/32/25754_2.png) [@fly\_high](https://forum.ghost.org/u/fly_high)\
**Post date:** [September 18, 2023, 2:22am UTC](https://forum.ghost.org/t/reverse-proxy-using-apache-and-cloudflare/41254/7 "2023-09-18T02:22:05Z")

</div>

so close!

i have the blog on [example.com/blog/](http://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

```auto
## routes.yaml

routes:

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

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

```

and chatgpt 4 suggested

```auto
routes:

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

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

```

and the worker ( also thanks to chatgpt)

```auto
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? 🫣

**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
