How do I configure nginx to serve some pages by express server & rest by ghost?

I want to create a website where few pages like

domainname.com, about, contact should be served by an express webserver & rest by ghost.
I am guessing I need to make some changes in nginx for this. Any idea how can I accomplish this? Currently I have default nginx configuration installed by ghost?

Here’s an example:

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name example.com;

    location ~ /contact {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:3000;
        proxy_redirect off;
    }

    location /blog {
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2368;
        proxy_redirect off;
    }

    location ~ /.well-known {
        allow all;
    }

    client_max_body_size 50m;
}
2 Likes

Solved this using http-middleware-proxy -> https://github.com/chimurai/http-proxy-middleware
Only directing / to express server and rest to ghost.

Live site -> https://apmtools.io | Ghots pages -> https://apmtools.io/getting-started/welcome

Installed ghost in root domain. nginx directing request to root domain on express server. Using http-proxy-middleware in express to proxy to ghost for non root pages