Setting up ghost blog /blog with Netlify site

Here’s my issue. I have a site running at example.com, and ghost blog at blog.example.com. I want to setup my blog to example.com/blog.

I’ve tried setting up proxy redirect using netlify.toml from /blog/* to https://example.com/blog/:splat.

But the problem is, when ghost generates the site, the post & sitemap links to blog.example.com. On top of that there are more urls like /tag, /author and so on that is used in ghost.

To set this up right, I need to setup ghost url as example.com/blog. But in this case, proxying wont’ work. On top of that, the server with ghost blog also needs an ssl certificate for same domain as the Netlify domain. I’m not able to set that up either.

So how can I do this right? How can I setup a ghost blog on example.com/blog and Netlify site on example.com

Hi @rison I haven’t used ghost myself yet, but what are the exact errors your getting when proxying your ghost blog? Can you share a link to your site so we can see? And yes, you would have to proxy every route that ghost needs in order for it to work. There isn’t a simple solution for this, but if the folder structure for ghost blogs is standard then you can write it once and just use it. Also, If the Ghost blog doesn’t use relative paths then it will attempt to load resources from your blog directly rather than via the netlify proxy.

I’d guess there should be a way to set the equivalent of “BaseURL” for the content ghost generates to “/blog” instead of “example.com/blog”. This will work if all your references are relative (/... instead of https://...)

The problem is the ghost uses the configured url to generate sitemaps and for accessing content. So if I set the main url to be https://example.com:

I cannot set the proxy url in netlify since it would look like /blog/* https://example.com/:splat. But example.com is already configured to netlify. Since netlify doesn’t allow proxying to another ip address, how would i handle this?

I tried setting up ghost to use https://example.com as the url and setting up nginx to also use https://blog.example.com to the same ghost instance. That way, I could proxy netlify to use blog.example.com. But I couldn’t get that to work either.

Any suggestion?

My usual recommendation would be to use a domain name for the blog which doesn’t duplicate the domain name the Netlify site uses. However, you state that you have already done this.

I just checked the staging deploy you mentioned above, and there are redirects for /blog/*. The string “blog” doesn’t appear anywhere in any of the redirect for that deploy.

Otherwise, the solution you mentioned should be working. The solution here will be to confirm that the redirects are all being loaded correctly.

Are you using netlify.toml or a _redirects file for defining redirects? Are you sure it is being copied to the publish directory during the build?

If you are using _redirects, you might try downloading the deploy to see what it contains. This is where to find the download deploy button (screenshot below).

I had updated the staging site, which is why the /blog redirects are missing. I"m using _redirects. Here is a snapshot from then. I’m able to get the blog on /blog.

But here is the problem: for ghost to use example.com in sitemap, I need to set the ghost url as mentioned here: https://ghost.org/faq/change-configured-site-url/. It also uses this for all post & tags links within the site.

If I change it to that, I don’t have a url to proxy redirects from netlify. Because it needs to proxy from /blog to example.com/blog/ which doesn’t make sense since example.com is handled by netlify.

In usual nginx setup, you could setup /blog to use ghost, but since that’s managed by netlify, I’m not able to. If there was a way to proxy to an ip address that would work I think.

Hope that makes the problem clear.

I still don’t know if I understand it, but it is starting to sound like you may have to create your own sitemap rather than using the built-in one for this use case.

Or you make the blog the primary part of the site and proxy other paths to a second site where you create the sitemap manually…

@fool This problem is still there. Please provide us a way to use Netlify website with example.com/blog working with a Ghost server

Hi, @thellimist, I see you have asked this question in a different topic here. I’ll follow-up with a reply there.

I have posted to this link, reposting here in case it’s useful for someoone

How to make Ghost and Netlify work with /blog (hint: Cloudflare Workers) | by Kan Yilmaz | Medium

I have wrote a hack on how to do it. It’d be great if Netlify allowed reverse proxy functionalities. I don’t necessarily recommend this solution to anyone. It’s a hack to get going without more headaches.

Hi, @thellimist, you can proxy using Netlify. You cannot run server side code though (except for Functions).

As I replied in the other thread, there is a much simpler solution for this issue and I’ve tried to explain it there.

If you want more assistance with this, please reply there (not to this topic) with the requested information.

I am facing the same issue with wordpress.
On NGINX I have been using option “filter” which rewrites all links in the content of the actual page:

sub_filter  "https://blog.domain.com/wp-content" "https://domain.com/blog/wp-content";
sub_filter "https://blog.domain.com/wp-login.php" "https://domain.com/blog/wp-login.php";
sub_filter "https://blog.domain.com/wp-content" "https://domain.com/blog/wp-content";
sub_filter "https://blog.domain.com/wp-includes" "https://domain.com/blog/wp-includes";
sub_filter "https://blog.domain.com/wp-admin" "https://domain.com/blog/wp-admin";

sub_filter_once off;
sub_filter_types *;

What is the alternative with netlify to do the same?

Or which blogging platform works well with Netlify in this setup?

I am willing to migrate to any other.
But following is needed:

  1. content is served under blog.domain.com
  2. all links of the blog pages are Domain Blog | Domain, Website, and Ecommerce Tips for Small Businesses and not blog.domain.com

Hey @jokuja,
This post describes how to set up a site where your blog lives in its own repository but is accessed via domain.com/blog:
[Support Guide] Can I deploy multiple repositories in a single site?

In terms of blog frameworks, you may want to check out Netlify CMS (Start with a Template | Netlify CMS | Open-Source Content Management System) or some of the static site generators here:
https://www.staticgen.com/

Let us know if that addresses your question or if we can help with anything else!