RStudio Server only accessible when port 8787 is fully open in firewall configs

Hi all, I'm moving the first steps with RStudio Server to forgive me if I'm missing something simple.

I have installed RStudio Server (the free version) on an Ubuntu machine with a public IP address.

The idea now would be to limit the access to the platform only to users that have machines belonging to a specific subset of IP addresses (the server IP belongs to to same subset), so using UFW I was trying a rule like

8787 ALLOW IN 195.236.116.0/24

but it does not seems to work (the login page is not accessible).

On the other hand if I use

8787/tcp ALLOW IN Anywhere

it works (and also if I disable UFW, of course), but that leave RStudio login page wide open to everyone from everywhere, and that is what I would like to avoid.

Any hint? Tanks in advance.

I just realized that if the OpenVPN server endpoint and any other service (rstudio server or else) are on the same machine, then the service cannot be requested with the public IP address of the machine, but rather with the private IP returned by the VPN client.