Replacing a VPS Reverse SSH Tunnel Without Losing Rollback
How I traced slow self-hosted services to a reverse SSH path, moved public traffic to Cloudflare Tunnel one hostname at a time, and kept a fallback route.

On this page
Audio edition
0:00 / 8:16
Ready
My self-hosted applications ran on a desktop at home. Cloudflare sent public traffic to a VPS, and the VPS forwarded it through a reverse SSH tunnel to Nginx on the home server. The design avoided inbound port forwarding and gave me a familiar SSH-based recovery path.
Then Mattermost messages began arriving late. API calls paused before returning, and WebSockets felt sticky. Nothing was fully down, so every component looked innocent on its own.
The problem was not Mattermost or an overloaded VPS. It was the route between the VPS and home. I replaced that public detour with Cloudflare Tunnel, but kept the old path available while I moved services one hostname at a time.
The Two Routes
The reverse SSH design sent every request through the VPS:
browser
-> Cloudflare edge
-> public VPS
-> reverse SSH tunnel
-> Nginx on the home server
-> local application
The replacement removed the VPS from the HTTP path:
browser
-> Cloudflare edge
-> Cloudflare Tunnel
-> cloudflared on the home server
-> Nginx on 127.0.0.1:80
-> local application
cloudflared initiates its connections from inside the home network, so the router still does not forward ports 80 or 443. Cloudflare terminates public TLS. Nginx continues to select the application from the request hostname.
That last detail mattered to me. The applications, Nginx configuration, and private listeners did not need to move merely because I changed the public transport.
Confirm Where the Delay Lives
A slow dashboard is not enough evidence to replace a tunnel. I first timed the application directly:
curl -sS -o /dev/null \
-w 'connect=%{time_connect} ttfb=%{time_starttransfer} total=%{time_total}\n' \
http://127.0.0.1:8065/api/v4/system/ping
Then I sent the same request through local Nginx with the public host header:
curl -sS -o /dev/null \
-H 'Host: chat.example.net' \
-w 'connect=%{time_connect} ttfb=%{time_starttransfer} total=%{time_total}\n' \
http://127.0.0.1/api/v4/system/ping
Both returned in under a millisecond. CPU was idle, memory was available, storage had no I/O wait, and Mattermost had no backlog. Through the public hostname, the same request averaged a little over one second and sometimes approached three seconds. DNS and TLS setup were comparatively quick; most of the delay appeared before the first byte from the origin.
I compared the general Internet path with the route to the VPS:
ping -c 20 1.1.1.1
ping -c 20 <VPS_ADDRESS>
mtr -T -P 443 -rwnc 10 1.1.1.1
mtr -T -P 22 -rwnc 10 <VPS_ADDRESS>
The nearby control target had low latency and no observed loss. The VPS path was roughly a quarter of a second away and unstable. Routers can deprioritize diagnostic packets, so I did not treat mtr as a verdict. The live SSH socket gave me stronger evidence:
ss -tinp | grep -A2 '<VPS_ADDRESS>:22'
journalctl -u reverse-http-tunnel.service --since today
The SSH connection showed a collapsed congestion window and a large retransmitted-byte count. Its service log showed timeouts, failed forwarding attempts, and reconnections. The VPS itself was not busy, and general Internet access from home was healthy during the tests. The weak link was the path carrying the reverse SSH connection.
That evidence set the scope of the change: replace the HTTP transport, not the applications behind it.
Keep Nginx as the Local Boundary
I configured and tested Nginx before adding the new public route. A reduced Mattermost virtual host looks like this:
server {
listen 80;
listen [::]:80;
server_name chat.example.net;
location ~ /api/v[0-9]+/(users/)?websocket$ {
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8065;
proxy_read_timeout 3600s;
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8065;
}
}
The explicit WebSocket location preserves Mattermost live updates. For an ordinary HTTP application, the second location block is enough.
Validate Nginx and test the hostname locally:
sudo nginx -t
sudo systemctl reload nginx
curl -i \
-H 'Host: chat.example.net' \
http://127.0.0.1/api/v4/system/ping
A tunnel can report healthy while Nginx is selecting the wrong virtual host or the application behind it is down. Fix the local route first.
Create the Tunnel
In the Cloudflare dashboard:
- Open Networking > Tunnels.
- Select Create a tunnel and give it a descriptive name.
- Choose the home server’s operating system.
- Run the installation command Cloudflare provides on that server.
- Wait for the connector to report that it is connected.
The connector should run as a service rather than depend on an open terminal. Check the service and recent logs:
systemctl status cloudflared
journalctl -u cloudflared --since '-10 minutes'
On a restrictive firewall, allow outbound TCP and UDP on port 7844. cloudflared uses QUIC over UDP or HTTP/2 over TCP and can fall back to the transport that is available. This is outbound access; the home router still needs no inbound forwarding rule.
Treat the connector token as a secret. Do not put the dashboard installation command, token, or service environment in a repository or a published tutorial.
Prove the New Path Before Cutover
Replacing the production wildcard first would turn any routing mistake into an outage. I published a temporary hostname through the new tunnel instead.
Open the tunnel’s Routes tab, select Add route > Published application, and enter a hostname such as tunnel-check.example.net. Set its service URL to:
http://127.0.0.1:80
Pointing the route at Nginx rather than directly at Mattermost keeps host routing, proxy headers, upload limits, and WebSocket handling in one place.
I gave the temporary hostname an unmistakable local endpoint:
server {
listen 80;
listen [::]:80;
server_name tunnel-check.example.net;
location = /healthz {
add_header X-Origin-Path "cloudflare-tunnel" always;
return 200 "tunnel-ok\n";
}
}
Then I tested the complete public path:
curl -i https://tunnel-check.example.net/healthz
For Mattermost, an API response does not exercise the transport used for live updates. I also tested the WebSocket upgrade on a temporary Mattermost hostname:
KEY=$(openssl rand -base64 16)
curl --http1.1 -i -N --max-time 4 \
-H 'Connection: Upgrade' \
-H 'Upgrade: websocket' \
-H 'Sec-WebSocket-Version: 13' \
-H "Sec-WebSocket-Key: $KEY" \
https://chat-test.example.net/api/v4/websocket
The expected opening response was:
HTTP/1.1 101 Switching Protocols
If ordinary HTTP works but this test fails, inspect the Nginx WebSocket path and upgrade headers before changing the tunnel.
Move One Hostname at a Time
My existing wildcard DNS record still sent unmatched subdomains to the VPS. I left it in place and added exact published application routes for the new tunnel:
static.example.net -> new tunnel
api.example.net -> new tunnel
chat.example.net -> new tunnel
*.example.net -> old VPS
An exact DNS name takes precedence over the wildcard. If a migrated service failed, removing its exact route restored the old wildcard path without redesigning either side.
I moved a static site first, then ordinary APIs, then applications with uploads and long responses. Mattermost moved last, after its temporary hostname passed both the API and WebSocket checks.
The production checks were deliberately small:
curl -fsS https://chat.example.net/api/v4/system/ping
curl -fsS https://api.example.net/health
curl -fsS https://static.example.net/
On the uncached Mattermost ping endpoint, warm requests fell from an inconsistent one-to-three-second range to roughly half a second on the new path. The reverse-tunnel timeouts also disappeared from the request path. These are observations from this network and workload, not a general Cloudflare Tunnel benchmark.
Add Services Without Adding Connectors
The tunnel service URL stays pointed at http://127.0.0.1:80. Each additional application gets its own Nginx virtual host and published application route:
server {
listen 80;
listen [::]:80;
server_name notes.example.net;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:4000;
}
}
One cloudflared service can carry several published application routes. Nginx uses the original hostname to choose the local application. A wildcard route can cover many first-level subdomains on one server, but Nginx still needs a matching virtual host for each real application; otherwise its default server answers.
A wildcard also cannot choose automatically between independent servers. Use exact hostnames for services that live elsewhere, or create a separate namespace or load-balancing design when failover is the actual requirement.
Keep a Separate Recovery Path
The new tunnel replaced public HTTP ingress. I did not make it replace administrative access in the same change.
I kept a separate reverse SSH administrative tunnel to the VPS while the new path settled. The HTTP reverse tunnel remained available beneath the wildcard until each hostname had been observed on the new route.
That left three distinct paths:
public web traffic Cloudflare Tunnel
administrative fallback reverse SSH
local application access 127.0.0.1 and Nginx
The administrative route can later move to Cloudflare Access, WireGuard, Tailscale, or another private network. Bundling that decision into the web migration would only make rollback harder.
The applications did not move. Nginx did not move. The home router still exposed no inbound ports. I changed the unreliable transport, verified the new one at each layer, and kept the old route until it was no longer needed.



