0

I am trying to route the traffic from an nginx, to a specific IP, corresponding to a path.

Basically if I am accessing http://example.com/192.168.0.2/something, I want to redirect the traffic to the pod with that specific IP (the result should be https://192.168.0.2/something).

I tried this (and multiple variations) but it doesn't seem to work.

location ~* "([0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3})\/(.*)" {
       proxy_pass http://192.168.219.174:8080$uri;
       proxy_set_header Host $host;
}

I even tried a static version (and multiple variations) like below

location ~* "/test/" {
       rewrite "/test/(.*)" /$1 break;
       proxy_pass http://192.168.219.174:8080
       proxy_set_header Host $host;
} 

Is there any way to achieve this?

Ivan Shatsky
  • 2,360
  • 2
  • 6
  • 17
zozo
  • 753
  • 3
  • 11
  • 22

1 Answers1

0

I don't understand how your config correspond with your question (I see the only backend with the static IP address 192.168.219.174), maybe you mean something like

location ~* "(?<pod_ip>[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3}\.[0-9]{0,3})(?<route>/.*)" {
    rewrite ^ $route break;
    proxy_pass http://$pod_ip;
}
Ivan Shatsky
  • 2,360
  • 2
  • 6
  • 17