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.