Host header in upstream requests

Hi,

We are using nginx for load balancing dynamically discovered upstream
endpoints. We are in need to attach upstream hostname as header Host in
upstream requests. For example below is my existing conf extract.

upstream products {
server hostname1:port1;
server hostname2:port2;
}
server {
location /products {
proxy_pass http://products
}
}

All requests are load balanced and working fine. Now we are in need to
add
http header “Host: hostnameX” (ex: hostname1 or hostname2, not its IP)
in
all requests to upstream. How can we get this done in nginx?

Regards

Use variables list to determine what is available to you:
http://nginx.org/en/docs/varindex.html

B. R.

On Sat, Mar 14, 2015 at 10:12 PM, Sapient N. [email protected]

Already tried $upstream_addr which unfortunately gives IP:port instead
of
hostname:port. My upstream needs hostname listed in conf instead of IP

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,257252,257258#msg-257258

I don’t think that something other than manual address-hostname pairs
maintainance can help you

map $upstream_addr $upstream_hostname {
10.0.0.1:80 hostname1;
10.0.0.2:80 hostname2;
}

proxy_set_header Host $upstream_hostname;

15.03.15 17:19, sapientcloud пишет:

Already tried $upstream_addr which unfortunately gives IP:port instead of
hostname:port. My upstream needs hostname listed in conf instead of IP

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,257252,257258#msg-257258


nginx mailing list
[email protected]
http://mailman.nginx.org/mailman/listinfo/nginx


br,
Dmitry Pryadko

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs