I have a python(flask) webapp. It is accessible by nginx in front of it.
Let, my domain is: http://domain.com
My web app is running on http://127.0.0.1:5000
nginx config:
upstream fapp {
server 127.0.0.1:5000;
}
server {
listen 80;
server_name domain.com www.domain.com;
location {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://fapp/;
proxy_intercept_errors on;
}
}
This app has two functionality or route:
Let, first one will give a page with some graphical details of data id 1 and second one will give the details without any graphical view.
What I want is a way if I hit http://domain.com/data/1 , nginx will give me data from either "http://127.0.0.1/dataone/1" or "http://127.0.0.1/datatwo/1".
How can I do that?
UPDATE 1: From the clue of @Oldskool, I did look at split clients module.
upstream fapp {
server 127.0.0.1:5000;
}
split_clients "${remote_addr}" $mydata {
50% "dataone";
50% "datatwo";
* "";
}
server {
listen 80;
server_name domain.com www.domain.com;
location {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://fapp/;
proxy_intercept_errors on;
}
location /data/ {
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://fapp/${mydata}/;
proxy_intercept_errors on;
}
}
But problem is if i access http://domain.com/data/1 or http://domain.com/data/35 or anything on that number is not working, it redirects to the url http://fapp/dataone/1 or 35. Is there anymore things to add or I am doing it wrong?
0 Answers