Skip to main content

Posts

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 127.0.0.1:8080; server 127.0.0.1:8081; server 127.0.0.1:8082; } upstream platinum { server 127.0.0.1:8083; server 127.0.0.1:8084; server 127.0.0.1:8085; } upstream silver { server 127.0.0.1:8086; server 127.0.0.1:8087; } # 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; p...