1

I have a reverse proxy setup with NGINX and behind my reverse proxy, I have two VPN Servers; one for students and one for admin, which requires UI access for management purposes.

Student's VPN UI:  192.168.101.10:443
Admin's VPN UI:    192.168.101.6:443

In production, I have only one single DNS name vpn.internal.example.com and I am trying to create a reverse proxy based on the specified trailing slash:

Incoming Request:
https://vpn.internal.example.com/students/foo/bar -> https://192.168.101.10/foo/bar
https://vpn.internal.example.com/admin/foo/bar    -> https://192.168.101.6/foo/bar

Basically, any incoming request should be Proxy_pass without the URI to the internal VPN Server's but when the request is sent back to the user, the trailing slash should be amended.

Returning Request:
https://192.168.101.10/foo/bar ->   https://vpn.internal.example.com/student/foo/bar
https://192.168.101.6/foo/bar  ->   https://vpn.internal.example.com/admin/foo/bar

I was hoping that this simple configuration would do the trick, I'm only showing a portion of the config for simplicity:

upstream vpn-student {
    server 192.168.101.10:443;
}

server {
    listen 443 ssl;
    ...

    server_name vpn.internal.example.com;
    location /student/ {
        proxy_pass https://vpn-student/;
        proxy_ssl_verify off;
        proxy_set_header Host $http_host;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Accept-Encoding "";
        sub_filter "https://vpn-student/" "https://vpn-student/student/";
        sub_filter_once off;
    }
}

I tried using the sub_filter option as shown in this post. But didn't have much success.

Also, sometimes when I type vpn.internal.example.com/students/ the web URL reverts back to vpn.internal.example.com

Perhaps someone could shed light on How to solve this issue? Thank you!

nickcrv06
  • 127
  • 11
  • You should use regular expressions in your location block. Create a group for everything after the /student/ and refer to it in the proxy_pass command. I hope i pushed you in the right direction, even tho i didnt give a full solution. – Likqez Jun 13 '23 at 00:15
  • I tried adding `location ~ ^/student/(.*)$ {` to the location block, as well as something like `proxy_pass https://vpn-student/$1$is_args$args;`. When I type `https://$url/student/login`, the login page shows but when authenticating the server have a general failure, seems that it cannot send/receive the request when /student/ trailing slash is present. If I type `https://$url/student/` then the browser sends me back to `https://$url/`. You did something! But still far off of the end result :/ – nickcrv06 Jun 13 '23 at 00:28

0 Answers0