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