Reverse proxying subpaths to articles

Hi everyone,

I am reverse proxying ghost using Nginx with http://www-news as my vm ip address.

  # reverse proxy news
  location /news {
    if (-f /etc/nginx/maintenance/NEWS.txt) {
      return 503;
    }
    access_log /var/log/nginx/access.log combined if=$log_4xx_5xx;
    proxy_pass http://www-news;
    include snippets/common/proxy-params.conf;
  }

This configuration work well; however, I would like to reverse proxy multiple subdirectories such as /about, etc. to articles in ghost.

I was wondering how such configuration would be possible since it seems like I can only reverse proxy using the one url that I specify in the ghost config file.

Is there a reason you can’t configure dynamic routing in Ghost, and then group all of the paths together?

e.g.

location ~ /(news|blog|stories) {
  # ...
}

Thank you for your quick reply, @vikaspotluri123.

For now I am working on reverse proxing a test page /search and get Cannot GET /search in the browser and 404 not found as a status code.

This is what we currently have for routes.yaml

routes:
  /rss/:
    template: rss
    content_type: text/xml
  /search/:
    template: search-results
  /about/:
    data: post.about
    template: post

and our config.production.json the url is set as

"url": "https://www.freecodecamp.dev/news/",

and here is we how are trying to reverse proxy to the search page for instance:

  # reverse proxy news
  location /news {
    if (-f /etc/nginx/maintenance/NEWS.txt) {
      return 503;
    }
    access_log /var/log/nginx/access.log combined if=$log_4xx_5xx;
    proxy_pass http://www-news-dev;
    include snippets/common/proxy-params.conf;
  }

  # reverse proxy search
  location /search {
    if (-f /etc/nginx/maintenance/NEWS.txt) {
      return 503;
    }
    access_log /var/log/nginx/access.log combined if=$log_4xx_5xx;
    proxy_pass http://www-news-dev/search;
    include snippets/common/proxy-params.conf;
  }

Although when I change the url from freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More to https://www.freecodecamp.dev/ in the config.production.json I am able to go to /search; however the styles would not load and /news would load a ghost page but with a 404.

Any suggestions or feedback is appreciated.

So if you set the path to /news in your Ghost config, all of the routes will be based on that…

So /search is really /news/search etc.

I have a feeling the reason styles might not be loading is because Ghost also has an assets path that’s used for theme assets and whatnot. If you’re only proxying /search and /news to ghost, the assets are going to proxy to (for example) your static files, which don’t have the assets Ghost is looking for.

1 Like