Two-VPS Private Proxy Architecture: Nginx Reverse Proxy Over Wireguard VPN
Overview
Proxy VPS: Public VPS running Nginx reverse proxy with its own public IP.
Backend VPS: Origin VPS running your service (e.g., Gitea, Forgejo), completely private.
Wireguard VPN: Encrypted private tunnel connecting Proxy VPS and Backend VPS.
Traffic flow: Client → Proxy VPS → Wireguard VPN → Backend VPS (service).
Prerequisites
Two Linux VPS servers (Ubuntu recommended).
A domain or subdomain for your service.
Basic Linux command line knowledge.
1. Generate Wireguard Keys on Both VPSes
wg genkey | tee privatekey | wg pubkey > publickey
chmod 600 privatekey publickeyprivatekeyholds your private key.publickeyholds your public key.
2. Configure Wireguard on Proxy VPS
Create /etc/wireguard/wg0.conf:
Enable and start:
3. Configure Wireguard on Backend VPS
Create /etc/wireguard/wg0.conf:
Enable and start:
4. Ensure Backend App Port Is Not Publicly Exposed
4.1 Bind the Service to the VPN IP
Configure your app (Gitea, forgejo, etc) to listen only on VPN IP 10.200.200.2.
Example for Gitea (app.ini):
This restricts the app to accept connections only over the secure VPN.
4.2 Firewall Configuration on Backend VPS
Block all incoming traffic except from Proxy VPS VPN IP on the service port (3000):
Only the Proxy VPS can access your backend service port.
4.3 Verify Port Binding and Traffic Restrictions
Check that service is listening correctly:
Expected output shows service bound to 10.200.200.2:3000 or 127.0.0.1:3000, NOT all interfaces (0.0.0.0).
4.4 Optional: NAT Port Forwarding on Proxy VPS
Alternatively or additionally, on Proxy VPS use iptables to forward incoming public port 443 traffic to backend VPN IP + port 3000:
Add to Wireguard config /etc/wireguard/wg0.conf on Proxy VPS for automation:
5. Configure Nginx on Proxy VPS
Install Nginx and configure /etc/nginx/sites-available/gitproxy:
Enable site and reload Nginx:
6. Configure DNS and SSL
Point your domain DNS A record to Proxy VPS public IP.
Obtain SSL with Certbot on Proxy VPS:
7. Test Your Setup
Visit:
Access your service securely via the Proxy VPS. Origin VPS IP remains hidden.
Summary Table
Wireguard key gen
Secure keys for VPN connection
Wireguard VPN config
Encrypted tunnel between VPSes
Bind app to VPN IP
Restrict app accessibility
Backend firewall rules
Allow service port only from Proxy VPN IP
Nginx reverse proxy
Proxy requests securely
DNS and SSL setup
Secure domain pointing and encryption
Last updated