Upstream host name or address

is it possible to find upstream host which serves as proxy for a
i know that $upstream_addr is the key ; but i need to set the address
with set_proxy_headdr as host
but $upstream_addr return address and port together

upstream test

location /
proxy_set_header Host $upstream_addr; ---------> fail cause it set for
example but i need
proxy_pass http://test;

any suggestion ?

thank you in advance…

Posted at Nginx Forum:

i forgot to add server in above upstream samples;;but my main config is
i just wanted to show an example of what i wanna do…
upstream test

thanks again;
i hope someone help me…

Posted at Nginx Forum:


On Sun, Jun 19, 2011 at 07:26:58AM -0400, torajx wrote:;

any suggestion ?

Request is created only once and you can’t set different headers
when working with different servers in upstream. Servers in
upstream block must accept identical requests.

(Moreover, $upstream_addr isn’t an address of upstream server nginx is
talking to, but a list of servers nginx have talked to during
handling of a request. And usually it won’t contain anything
while creating request to upstream.)

If you really need different requests to different backend servers
you’ll have to use different proxy_pass’es for that (or use
variables). E.g. in 0.9.6+ you may do something like this:

map $remote_addr $backend {
    default          "should not happen";

location / {
    proxy_pass http://$backend;

(no need for proxy_set_header here, as $proxy_host will resolve to
the backend’s ip address and default “proxy_set_header Host
$proxy_host;” will do what you want)

But note that recommended aproach is to actually configure
identical backend hosts, not adapt requests for each one.

Maxim D.

by the way in my nginx server and i forgot to remove real
name at the end…no problem :wink:
it means users can type
and in csupdate there is some link to images that i mention in images

Posted at Nginx Forum:

sorry againa and again
i forgot one line again i have this line in my csupdate location too’

my csupdate location is like this finally :

location /csupdate {
proxy_pass http://mysites_hash/csupdate;
proxy_set_header Host;

but this works when i have only one server in mysites_has upstream

Posted at Nginx Forum:

hi again and thank you fo reply
this is my main config file; sorry i remove real ip address and site

upstream mysites {
server weight=5;

server weight=3;

upstream mysites_hash {
ip_hash; #base on clinet ip address and can not use weight;


upstream myimages {
server {
listen 80;
set $tmp tempstr;
access_log var/log/nx_csupdate_access.log main;
log_format main “$upstream_addr”;

   location /  {
         deny all;
   location /csupdate/images {
         proxy_pass      http://myimages;
   location /csupdate {
      proxy_pass      http://mysites_hash;
      proxy_set_header Host;

as you can see i commented my 2th server in my upstream;
the proxy_set_header line in location /csupdate was the only soloution
that solved
my problem; because my servers (, 2) will redirect users base
on some condition
and without proxy_set_header line the browsers fall in endless loop and
retun errors;

for $upstream_addr in can see in my log files as i
formated simply likme above;
but what is soloution in i want to use server too ??

thank you in advance

Posted at Nginx Forum: