Nginx proxy_pass with variables

577 Views Asked by At

I've got 2 upstreams and described the logic of cookie check in nginx config:

upstream back {
    server backend-release.mynamespace.svc.cluster.local;
 }
upstream back-preprod {
    server backend-preprod.mynamespace.svc.cluster.local;
}

map $http_cookie $back_upstream {
    default back;
    ~*is-preprod=true back-preprod;
}

location ~ ^/(api|graphql) {
    proxy_pass http://$back_upstream;
}
location /rest/ {
    proxy_pass http://$back_upstream/rest/;
}

When i call GET http://my-url/api/..., it works, but i always get 404 for GET http://my-url/rest/..

How to fix it?

1

There are 1 best solutions below

0
On

I found solution:

upstream back {
    server backend-release.mynamespace.svc.cluster.local;
}
upstream back-preprod {
    server backend-preprod.mynamespace.svc.cluster.local;
}

map $http_cookie $back_upstream {
    default back;
    ~*is-preprod=true back-preprod;
}

location ~ ^/(api|graphql|rest) {
    proxy_pass http://$back_upstream;
}

location /rest/ is unnecessary in this case.