Welcome! Log In Create A New Profile

Advanced

Separated reverse proxy for different users

ivy
August 25, 2017 06:33AM
Hi, I'm relatively new to HTTP servers and absolutely new to nginx.
I have HTTP server which should ask user credentials and redirect every user to its own reverse proxy.

The initial setting is:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
set $auth_status 100;
server_name localhost;
root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;

location / {
try_files $uri $uri/ =404;
auth_basic "restricted content";
auth_basic_user_file "/home/secure/.passwords";
auth_request_set $auth_status $upstream_status;

if ($remote_user = "ivy") {
proxy_pass http://localhost:10080;
break;
}
if ($remote_user = "john") {
proxy_pass http://localhost:10081;
break;
}
}

It works OK. However, I think it's pretty ugly to have separated "if" per user. 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: "..."
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: "..."

It's clear that I miss something in the documentation.
Please, help to build a map for reverse proxy by user authentication properly.

Thank you.
Subject Author Posted

Separated reverse proxy for different users

ivy August 25, 2017 06:33AM

Re: Separated reverse proxy for different users

Francis Daly August 30, 2017 02:10PM

Re: Separated reverse proxy for different users

ivy September 02, 2017 03:53PM

Re: Separated reverse proxy for different users

Francis Daly September 03, 2017 05:18AM

Re: Separated reverse proxy for different users

ivy September 15, 2017 01:20PM

Re: Separated reverse proxy for different users

Ish Sookun September 03, 2017 07:20AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 162
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready