Score:0

NGINX reverse_proxy with subpath and regex

cn flag

I have a site running on localhost:8001 and I would like it to be accessible on different paths. I need to extract part of the path using regex.

This does work:

server {
    location /user/amy/ {
        proxy_pass http://localhost:8001/;
    }
}

(but it breaks if I remove the slash after 8001).

However, the username can be dynamic, for example:

mydomain.com/user/amy/ --> localhost:8081/
mydomain.com/user/bob/foo --> localhost:8081/foo

In both cases I want to get the username out in order to do a subrequest. Here is what I have tried:

server {
    location ~ ^/user/([a-z]+)/(.*)$ {
        set $user $1; # do stuff with this later
        proxy_pass http://localhost:8001/$2;
    }
}

It doesn't work: I get a too many redirects error. I've tried many things and nothing seems to work. I want it to work exactly like the prefix example I gave first, except that I extract the username for further processing. Any help would be massively appreciated.

Score:-1
ar flag

I suggest you try Nginx Proxy Manager.

Nikita Kipriyanov avatar
za flag
And so what? Explain how to do this using your "Nginx Proxy Manager".
Code Alex avatar
ar flag
You add a proxy host and then add custom locations. You will see the option in the Gui of Nginx Proxy Manager
I sit in a Tesla and translated this thread with Ai:

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.