Upstream host name or address

hi,
is it possible to find upstream host which serves as proxy for a
connection;
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
{
ip_hash;
192.168.1.1;
192.168.1.2;
}

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

any suggestion ?

thank you in advance…

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

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

thanks again;
i hope someone help me…

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

Hello!

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

192.168.1.1;

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";
    ~[02468]\.\d+$   192.168.1.1;
    ~[13579]\.\d+$   192.168.1.2;
}

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 nx.chare.ir in my nginx server and i forgot to remove real
name at the end…no problem :wink:
it means users can type nx.chare.ir/csupdate
and in csupdate there is some link to images that i mention in images
location…

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

sorry againa and again
i forgot one line again i have this line in my csupdate location too’
proxy_redirect http://192.168.1.1/csupdate
http://nx.chare.ir/csupdate;

my csupdate location is like this finally :

location /csupdate {
proxy_pass http://mysites_hash/csupdate;
proxy_set_header Host 192.168.1.1;
proxy_redirect http://192.168.1.1/csupdate
http://nx.chare.ir/csupdate;
}

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

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

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

upstream mysites {
server 192.168.1.1 weight=5;

server 192.168.1.2 weight=3;

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

server 192.168.1.2;

}
upstream myimages {
server images.mysite.com;
}
server {
listen 80;
server_name nx.chare.ir;
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    192.168.1.1;
   }

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 (192.168.1.1, 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 192.168.1.1:80 in my log files as i
formated simply likme above;
but what is soloution in i want to use 192.168.1.2 server too ??

thank you in advance

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

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