Separated reverse proxy for different users

Francis Daly francis at daoine.org
Wed Aug 30 18:09:37 UTC 2017


On Fri, Aug 25, 2017 at 06:33:11AM -0400, ivy wrote:

Hi there,

> Therefore, I want to add a map:
>     map $remote_user $rp_port {
>        include /home/secure/reverse_proxy.map;
>     }
> 
> The map contains:
> ivy 10080;
> john 10081;
> 
> From documentation I understood this should come before server definition.
> Then I tried to replace all "ifs" in server body with:
>           proxy_pass http://localhost:$rp_port
> 
> This configuration gives following errors:
> 2017/08/25 06:29:38 [error] 26582#26582: *631 invalid port in upstream
> "localhost:", client: ..., server: localhost, request: "GET / HTTP/1.1",
> host: "..."

That is because your map does not have a "default" value, so when
$remote_user is empty or does not match one of your listed names,
$rp_port is empty and your configuration is effectively

  proxy_pass http://localhost:;

which is invalid. Simplest fix is to always have a value for $rp_port.

> 2017/08/25 06:29:48 [error] 26582#26582: *632 no resolver defined to resolve
> localhost, client: ..., server: localhost, request: "GET / HTTP/1.1", host:
> "..."

That is because you use a proxy_pass with variables, and this version of
nginx does not try to resolve the hostname at startup, instead resolving
it at processing time -- and you have not defined a resolver. Simplest
fix is to use 127.0.0.1 instead of localhost here.

	f
-- 
Francis Daly        francis at daoine.org


More information about the nginx mailing list