How to configure nginx for proxying scheme user-id=resource?

The task of the next:
There are several servers, each of which enshrined their users. You want to make all users a single entry point (single host). Use the url as http://mycloud.com/{user-id}/resource. Depending on user-id the request should be routed to a specific backend server. The list of users and their respective servers stored in the database.
I want to use nginx for routing, but do not know how to configure. After all, if a register location / proxy_pass for each user individually, it will be sooooo great config! Is there another way?
July 9th 19 at 12:49
1 answer
July 9th 19 at 12:51
Can use map to determine and find out.
I cookie to determine which server to send queries:
upstream backend {
least_conn;
 server 1.1.1.1;
 server 2.2.2.2;
 server 3.3.3.3;
}

map $cookie_server $upstream {
 default backend;
 1 1.1.1.1;
 2 2.2.2.2;
 3 3.3.3.3;
}
about map read, thanks! Yet, frankly, Your example do not understand. - kevon21 commented on July 9th 19 at 12:54
: if a visitor came with the cookie server=2 it sends to the backend address 2.2.2.2 - Giles_Funk63 commented on July 9th 19 at 12:57

Find more questions by tags Nginx