Score:0

Hosting multiple applications behind Nginx reverse proxy

cn flag

We're moving to an approach where several app instances are created for multiple use cases. In front of the whole stack, we use Nginx as a reverse proxy.

We define it like this:

    location /admin {
        rewrite /admin/(.*) /admin/$1  break;
        proxy_pass http://localhost:3000;
        proxy_set_header Connection "";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
    }

    location /client {
        rewrite /client/(.*) /client/$1  break;
        proxy_pass http://localhost:3001;
        proxy_set_header Connection "";
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
    }

The problem I have is - any URL normalisation drops the /app. So when I browse https://localhost/admin/page1 all the requests from the front end (including static files) https://localhost/page1

What I want to achieve is, when app segment is present, all the requests will hit a respective app server. Including static content and websockets requests.

djdomi avatar
za flag
show pls the full configuration `nginx -T`
Score:0
us flag

It is your application that generates the links to static resources in the HTML code it generates.

Therefore you must configure your application's base URL to match the location in your proxy case.

The rewrite statements in your configuration are not needed. They don't actually do anything.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.