Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Help With nginx Split Client Module
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Help With nginx Split Client Module

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:

http://127.0.0.1/dataone/1

http://127.0.0.1/datatwo/1

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".

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 anything more to add or am i doing it wrong?

Thanks in advance and please ignore my insolence.

Sign In or Register to comment.