1

Using NGINX as a reverse proxy, I want to tag which load balancer/proxy the request can in on, and pass that to the end app servers...

For example, we have 2 ingress connections, using round-robin DNS to 3 load balancers,

so, connection one has 3 pubic IP's and connection two has 3 IP's. each pair points to a load balancer and they're using proxy pass upstream to send traffic to the 10 web/app servers.

I want to tag which of the 3 LB's the request comes in on, I'd love to tag it based on the connection too, if you know how.

 upstream web_cluster { random; # web server ip addresses x 10 } location / { proxy_pass http://web_cluser; proxy_set_header Proxy $proxy_server_host_name; // here proxy_set_header Route $proxy_server_public_ip; // here proxy_pass_request_headers on; } 

The servers are all deployed via Ansible scripts, so I wouldn't be able to hard-code server names into the proxy_set_header options.

Thanks

1 Answer 1

1

To tag all this we could change your configuration file to use the map directive to map the remote IP address to the corresponding load balancer name, and the $proxy_host variable to set the Proxy-Host header.

upstream web_cluster { server 10.0.0.1; server 10.0.0.2; server 10.0.0.3; # add more servers here as needed } map $remote_addr $proxy_host { 192.168.1.1 "lb1"; 192.168.1.2 "lb2"; 192.168.1.3 "lb3"; # add more mappings here as needed } server { listen 80; server_name example.com; location / { proxy_pass http://web_cluster; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Proxy-Host $proxy_host; } } 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.