Welcome! Log In Create A New Profile

Advanced

Re: upstream host name or address

Maxim Dounin
June 19, 2011 05:42PM
Hello!

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

> 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 ?

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 Dounin

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

upstream host name or address

torajx June 19, 2011 07:26AM

Re: upstream host name or address

torajx June 19, 2011 07:43AM

Re: upstream host name or address

Maxim Dounin June 19, 2011 05:42PM

Re: upstream host name or address

torajx June 20, 2011 12:57AM

Re: upstream host name or address

torajx June 20, 2011 12:59AM

Re: upstream host name or address

torajx June 20, 2011 02:23AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 254
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready