Welcome! Log In Create A New Profile

Advanced

Re: Nginx as LB to redirect/return to upstream server instead of Proxy

Maxim Dounin
October 15, 2018 10:46AM
Hello!

On Mon, Oct 15, 2018 at 03:15:39PM +0200, Aleksandar Lazic wrote:

> Hi.
>
> Am 15.10.2018 um 09:08 schrieb anish10dec:
> > We want to use Nginx as LB in a way so that Nginx can return 301 or 302
> > redirect to client instead of Proxying request to backend/upstream servers.
> >
> > It is required as Server which is configured as LB is having limited
> > throughput of 1 Gbps while upstream servers are having throughput of 10Gbps
> > .
> >
> > We want users to directly connect to Upstream Server for Data delivery.
> > Nginx LB Server to make sure that all upstream are up and functional before
> > giving 301 or 302 redirect to any of upstream server
> >
> > Example:
> >
> > http://nginxlb.com/data/download
> >
> > Nginx LB Returns Redirected URL to Client 301 or 302 ( That upstream should
> > be up)
> >
> > http://upstreamserver1.com/data/download
> > http://upstreamserver2.com/data/download
> >
> > Is this possible by :
> >
> > return 301 http://$upstream_addr/data/download
>
> I would do this with maps, rewrite and upstream variables.
>
> https://nginx.org/en/docs/http/ngx_http_map_module.html
> https://nginx.org/en/docs/http/ngx_http_upstream_module.html#variables
> https://nginx.org/en/docs/http/ngx_http_rewrite_module.html
>
> Untested:
> ###
> map $upstream_addr $direct_domain {
> default nginxlb.com;
> IP1 upstreamserver1.com;
> IP2 upstreamserver2.com;
> }
>
> return 301 http://$direct_domain/data/download
> ###

This won't work, because the $upstream_addr variable won't be
available without an actual upstream connection.

To balance traffic to multiple servers without proxying, the
split_clients module can be used. For example, something like
this should world, balancing based on client's address (untested
though):

split_clients $remote_addr $domain {
50% upstreamserver1.com;
* upstreamserver2.com;
}

return 302 http://$domain/data/download;

Docs are available here:

http://nginx.org/en/docs/http/ngx_http_split_clients_module.html

Note thought that this won't do any checks on whether the upstream
server is up or not. If checks are needed, a better approach
might be to use some more sophisticated logic to return such
redirects. Most simple solution would be to actually proxy
requests to the upstream servers, and let these servers to return
actual redirects to themselves.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Nginx as LB to redirect/return to upstream server instead of Proxy

anish10dec October 15, 2018 03:08AM

Re: Nginx as LB to redirect/return to upstream server instead of Proxy

Aleksandar Lazic October 15, 2018 09:16AM

Re: Nginx as LB to redirect/return to upstream server instead of Proxy

Maxim Dounin October 15, 2018 10:46AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 63
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready