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…