Skip to main content


Showing posts from March, 2017

Select different backend pools based on the HTTP Headers in Nginx

Some scenarios we need to select different backend pools based on some attributes in the request.
Nginx has that capability to selecting different backend pools based on the request header value.

To accomplish this in Nginx you can use the following code in your configuration.

upstream gold { server; server; server; } upstream platinum { server; server; server; } upstream silver { server; server; } # map to different upstream backends based on header map $customer_type $pool { default "gold"; platinum "platinum"; silver "silver"; } server { listen 80; server_name localhost; location / { proxy_pass http://$pool; #standard proxy settings proxy_set_header X-Real-IP $remote_addr; proxy_redirect off; proxy_set_header X-For…