Hosting a publicly accessible website that is behind a VPN

Setup:

Ubuntu 20.04

VPN Unlimited

Nginx

Problem:

One of the uses for my server is to host a publicly accessible Nextcloud (file storage) instance. I have a domain name that periodically corrects itself to my public IP.

Without the VPN, the site works fine but with it on (and the domain pointing to the VPNs IP), it’s no longer accessible and I’m shown the default nginx “Welcome to nginx!” screen (which doesn’t seem to be my nginx instance because I’ve stopped the service).

I’m running the server behind VPN so that my traffic is encrypted as I also use my server for other stuff.

Considering it’s a public VPN (worth noting because I assume I will be assigned a random port by the VPN provider so maybe this is where I get blocked?), is it possible to have my server running on the VPN and still be publicly accessible?

End Goal:

Whether it’s through a VPN or some other utility, I want all (or better still just a single port) of my traffic encrypted and away from prying eyes

Networking is utterly confusing to me so any help would be appreciated

When you go to a website, you computer attempts to communicate on port 80 for http and 443 for http. Like you mentioned you will be assigned a random port. if at all, depending on the VPN provider, double check this. Either way you absolutely do not have access to 80/443 on the public VPN server. So you will need to access your website by going to <VPN IP/domain>:<VPN port>.

Instead of using a public VPN I would recommend renting a VPS and setting up that to act as the VPN server. Then you can port forward ports 80/443 and access your website like normal.

Whether it’s through a VPN or some other utility, I want all (or better still just a single port) of my traffic encrypted and away from prying eyes

A VPN is not the solution to this problem (for a service provider). HTTPS is the solution here. Your Nextcloud site presumably already uses TLS. So what benefit is adding a VPN in this case?

That’s what I was afraid of - I’ve messaged the VPN provider anyway to see if they have any useful info.

Theoretically then, I should be able to setup a VPS with a Raspberry Pi running Wireguard. I do have a spare one so I can play around with it and test it out but I assume there would be speed loss/latency running it through the Pi

This is the right answer, if you choose to go this route, this is a handy guide to achieve this. https://selfhosted.pro/hl/wireguard_vps/

Interesting, thanks for that, I have a spare Pi and seeing as this is just installing Wireguard, I should be able to do it on the Pi and route all traffic through there instead - at least to test and see if the network speed etc. holds up for my purposes

It should be pretty fast, specially if your VPS is close to your location and has good port speed.