VPS reverse proxy works on local Flask server but not NextCloud

I’ve used NextCloud for a few years now on a traditional ISP with dynamic DNS, so I’m fairly familiar with how it works with an accessible port 80/443. My new ISP (T-Mobile 5G) is double NAT. I can reverse proxy to a local Flask development server using a VPS configured as described below, but NextCloud from the same server gives a 504 Gateway Time-out error.

My current setup works as follows:

  1. A VPS with static IP is connected to the internet, ports 80 and 443 are open.
  2. I use ZeroTier to create a link to my local network with my local server
  3. nginx is used to reverse-proxy VPS incoming connections to the ZeroTier IP of my local server:
server {
  listen 80;
  location / {
    proxy_pass http://192.168.192.191;
}
}
server {
  listen 443;
  location / {
    proxy_pass http://192.168.192.191:443;
  }
}
  1. I run Flask to test the reverse proxy function, successfully accessing my local machine from the internet through the VPS static IP.
  2. I disable the Flask server and run NextCloud 22.2.0.2 on my local server with the VPS ZeroTier IP in trusted_proxies from NextCloud’s config.php.
  3. When I try to access NextCloud from:
  • localhost IP: working
  • ZeroTier IP of the local server from remote device also on ZeroTier: working (though this is not a trusted domain as currently configured so the appropriate warning appears)
  • ZeroTier IP of the VPS from any device also on ZeroTier: not working (504 error)
  • Static IP of the VPS from internet: not working (504 error)

I’m not forcing HTTPS anywhere yet so I would expect to see the HTTP site this way like on localhost/ZeroTier.

Has anybody tried this or have any suggestions? I’m very confused since the ports appear to be routing through the VPS properly. Thanks in advance!

Solved by running a PageKite Server on the VPS instead of ZeroTier. NextCloud works perfectly with it, including HTTPS.

The speeds aren’t the best despite ample bandwidth on both VPS and local network, but it does work. My best guess is that zlib compression/decompression CPU bottlenecks uploads/downloads at the VPS. All nodes involved have symmetric 100mbps or better connectivity, yet uploads/downloads never exceed 700KB/s. Not exactly speedy, but good enough.