web server – nginx serve two frontends that share same backend

In nginx, I want to serve two frontends that make requests to one backend. The main frontend going to be continue served on “/” location, and cloned frontend will be served on a subdirectory, let’s say /alpha.

My current nginx configuration is (without that clone frontend, /alpha):

server {
    ...

    location = /notification-auth {
        ...
    }

    location ~ /notifications/(\d+)$ {
        ...
    }

    location /api/ {
        ...
    }

    location /api/download/ {
        ...
    }

    location /download/ {
        ...
    }

    location /api/generate/ {
        ...
    }

    location /generate/ {
        ...
    }

    location / {
        root /srv/www/main;
        index index.html;
        try_files $uri /index.html;
    }

}

I want to add a block for /alpha‘s static content, let’s say:

location /alpha {
    root /srv/www/alpha;
    index index.html;
    try_files $uri /index.html;
}

But that /alpha‘s backend requests have to be redirected to main backend location, like /notification-auth, /notificatons, /api, /download and so on.

Like if somebody sent request to example.com/alpha/api/test, it should be redirected to example.com/api/test.

Read more here: Source link