0

Ok I'll try explain this as best I can. I've managed to setup to a subdirectory location /blog/ on the example.com server block (Website A) that successfully displays my blog on the subdomain blog.example.com.au server block (Website B), with the url as example.com/blog/.

However when I click any of the links on the homepage from example.com/blog/, it shows a 404 of Website A when it should link to an article on Website B.

Desired behaviour: example.com/blog/article links to blog.example.com/article while displaying example.com/blog/article

Actual behaviour: example.com/blog/article links to example.com/article while displaying example.com/article 404

I want to make sure /blog/ appears on every request to be passed to Website B through the /blog/ location block.

Here is my current server block for website A to serve the blog on website B:

server {
  server_name example.com;

...

  location ^~ /blog/ {
      proxy_pass https://blog.example.com.au/;
      proxy_set_header Host blog.example.com.au;
  }

  # This is needed to correctly serve static files for Website B and not have same 404 behaviour as explained above
  location /assets/ {
     proxy_pass https://blog.example.com.au/assets/; 
}

  # This is needed to correctly serve static files for Website B and not have same 404 behaviour as explained above
  location /content/ {
    proxy_pass http://blog.example.com.au/content/;
  }
}

If it helps Website A and B are both reverse proxied and working perfectly on their own in the same conf file:

upstream Website_A {
  server Website_A:8000;
}

upstream Website_B {
    server Website_B:2368;
}

...
koopmac
  • 127
  • 5

1 Answers1

2

Configure your backend with the correct base URL so it generates the correct links.

Since you seem to be using Ghost for your blog, the option is called url.

"url": "https://example.com.au/blog/"

Of course it would make more sense to proxy this directly to ghost instead of proxying it twice.

server {
    server_name example.com.au;

    # ...

    location /blog/ {
        proxy_pass http://Website_B:2368;
    }

}
Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
  • Great that worked when removing the trailing slash from `proxy_pass http://ghost`. But now I can't log in to the admin `Error: SQLITE_READONLY: attempt to write a readonly database`. My git push was raising a permission denied error earlier, so I changed the file permissions using `sudo chmod -R ug+w .;`. The permissions for ghost.db are now `-rw-r--r-- 1 michael michael`. Should I change the permissions of the `.db` file? – koopmac Sep 07 '20 at 23:07
  • There is no way to know without more information. And this would be a new question. If this answer solved your problem please accept it using the checkmark on the left. – Gerald Schneider Sep 08 '20 at 05:44