Welcome! Log In Create A New Profile


Re: Sending basic auth to "backend" servers

Maxim Dounin
May 26, 2016 09:26AM

On Wed, May 25, 2016 at 04:02:46PM -0400, jrhodes wrote:

> Hey everyone
> I'm trying to achieve something a little unique (have read a LOT of
> documentation and posts)
> I want to use ngnix as a LB to a handful of squid servers I have to
> distribute http requests on a round robin basis.
> Each squid web server in the "backend" accepts a unique username and
> password.
> Would anyone be able to point me in the right direction config wise on how
> to define a unique user/pass for each server in the load balanced pool?

Normal logic of load balancing in nginx assumes the same request can
be sent to multiple backend servers, and therefore it won't work
for you - as you need to construct unique request to each backend,
with it's own Authorization header.

To do what you want you may try distributing requests "by hand",
e.g., using the split_clients module:

split_client $remote_addr $backend {
50% backend1.example.com;
* backend2.example.com;

map $backend $backend_auth {
backend1.example.com QWxhZGRpbjpvcGVuIHNlc2FtZQ==;
backend2.example.com QWxhZGRpbjpvcGVuIHNlc2FtZQ==;

server {

location / {
proxy_pass http://$backend;
proxy_set_header Authorization "Basic $backend_auth";

More information can be found in the documentation here:


Maxim Dounin

nginx mailing list
Subject Author Posted

Sending basic auth to "backend" servers

jrhodes May 25, 2016 04:02PM

Re: Sending basic auth to "backend" servers

Maxim Dounin May 26, 2016 09:26AM

Re: Sending basic auth to "backend" servers

jrhodes May 26, 2016 03:07PM

Re: Sending basic auth to "backend" servers

jrhodes May 27, 2016 08:10AM

Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 70
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