# Self-host ProxVN on Ubuntu: from a fresh VPS to your first real tunnel

A complete practical tutorial with DNS records, copyable server/client commands, certificate pins, HTTPS tests, SMTP, backups and an upgrade plan.

Source: https://proxvn.io.vn/blog/self-host-server

The goal is a working service you can operate tomorrow, not just a green install message: your own website and Console, a verified client connection, an HTTPS tunnel from your laptop, and a recoverable server.

**Choose the right starting point:** to share a local app using the public ProxVN service, follow the [client tutorial](https://proxvn.io.vn/blog/run-client). You only need the client on your own computer for that path. This self-hosting article is for running your own public server and domain, including its updates, users and backups. A **VPS** is an online computer rented from a hosting provider; budget separately for that rental and your domain. See the [plain-language glossary](https://proxvn.io.vn/docs/glossary) if the server terms are new.

This walkthrough uses Ubuntu/Debian with systemd, an amd64/arm64 VPS, domain ` example.com `, origin IP ` 203.0.113.10 ` and control host ` tunnel.example.com `. Replace all example values. The address is reserved for documentation and is not a real ProxVN endpoint. Server and clients must use 9.x. A separate [Docker Compose path](https://proxvn.io.vn/docs/self-host#docker) is available if you prefer containers.

## 1. Know which machine runs each command

Your rented **VPS** forwards public visitors to the right client. **Local** is your laptop/PC where the application runs. Install the server only on the VPS; install the client on the local machine. Friends and webhook providers visit the public HTTPS URL or assigned public TCP/UDP address. Your local router normally needs no inbound port mapping for the client’s outbound connection. The example ` ubuntu ` SSH username and documentation IP below must be replaced with the credentials/address for your own VPS.

**VPS:** connect with your real SSH username/IP and prepare tools. Keep this session open throughout firewall changes.

```
ssh ubuntu@203.0.113.10
sudo apt-get update
sudo apt-get install -y curl ca-certificates openssl iproute2 dnsutils sqlite3 less
sudo ss -lntup
free -h
df -h /var
timedatectl status
```

Before continuing, check that another site does not need port 443. The installer refuses an existing owner there. It can bridge an existing nginx on port 80 for the selected domain, but it does not configure shared HTTPS proxying. On a shared VPS read the [coexistence notes](https://proxvn.io.vn/docs/self-host#prepare) and decide the port/IP plan first.

## 2. Create DNS records and choose your HTTPS trust model

**DNS** tells other computers which IP belongs to a domain. An ` A ` record points to an IPv4 address; ` @ ` is your main domain and ` * ` covers subdomains such as ` demo.example.com `. **HTTPS/TLS** encrypts the connection, and a trusted **certificate** lets a browser verify the website name. In Cloudflare instructions, **origin** means your VPS and **edge** means Cloudflare’s public gateway.

For this walkthrough create the following records in Cloudflare, with your real origin IP:

| Record | Value | Cloudflare proxy |
| --- | --- | --- |
| ` A @ ` | ` 203.0.113.10 ` | Proxied for this Cloudflare setup |
| ` A * ` | ` 203.0.113.10 ` | Proxied for HTTPS tunnel names |
| ` A tunnel ` | ` 203.0.113.10 ` | **DNS only** |

Select SSL/TLS **Full** for the generated self-signed origin certificate. Wait for the Cloudflare edge certificate to be active for your apex/wildcard. The tunnel record stays **DNS only** because clients need raw TCP/UDP connections outside the website proxy. If DNS has an old AAAA record, fix it rather than leaving some users pointed at a different origin.

```
dig +short example.com A
dig +short first-test.example.com A
dig +short tunnel.example.com A
```

Full encrypts the origin connection but does not authenticate that origin certificate. Once the basic flow works, install a certificate for ` example.com ` and ` *.example.com ` and choose Full (strict). Cloudflare Origin CA works for a proxied origin; direct browser access needs a publicly trusted CA instead. The server does not automatically obtain an ACME certificate. Follow the [certificate installation commands](https://proxvn.io.vn/docs/self-host#config) when hardening the setup.

## 3. Install the release on the VPS

```
curl -fsSLo install-server.sh https://proxvn.io.vn/install-server.sh
less install-server.sh
sudo bash install-server.sh \
  --domain example.com \
  --public-host tunnel.example.com \
  --ports 10000-20000 \
  --source https://proxvn.io.vn
```

Read the script before executing it as root. It verifies downloaded bundle hashes, creates the service user, places the website/server/downloads under ` /opt/proxvn `, writes the private environment under ` /etc/proxvn `, and puts persistent state in ` /var/lib/proxvn `. On shared hosts you can append ` --no-tune --no-swap --no-nginx ` if you manage host tuning, swap and nginx yourself; then supply any required HTTP bridge yourself.

The default tuning changes host-wide network/sysctl and journald settings, attempts 512–2048 MiB swap only when none exists, and installs service memory/file-descriptor limits. Busy public-range ports are excluded on first configuration and checked again at allocation time. Read the [exact flag and resource-limit reference](https://proxvn.io.vn/docs/self-host#install) rather than assuming the script only copies one executable.

## 4. Allow traffic without locking out SSH

In both your cloud firewall and host firewall, allow 443/tcp, the optional HTTP front door 80/tcp, 8882/tcp+udp and your selected 10000–20000/tcp+udp public range. Keep the API 8881 on loopback. Preserve the real SSH port. If UFW is already active, these are additive rules; do not run reset/enable blindly:

```
sudo ufw status verbose
sudo ufw allow 443/tcp
sudo ufw allow 80/tcp
sudo ufw allow 8882/tcp
sudo ufw allow 8882/udp
sudo ufw allow 10000:20000/tcp
sudo ufw allow 10000:20000/udp
```

If another service owns a port inside the public range, add it to ` PORT_EXCLUDE ` in the saved environment. Example: ` PORT_EXCLUDE=18787 `. Do not expose dashboard port 8881 to make Console work: ` https://example.com/console/ ` already routes through 443.

**Plan for DDoS separately.** DDoS is an overload attack from many sources. ProxVN’s application request/session limits can reduce some abuse; they cannot prevent an attack from filling the VPS network connection. A CDN such as Cloudflare can apply its filtering only to traffic proxied through it, such as the website and HTTP(S) tunnels in this setup. Direct TCP/UDP tunnels and client-control traffic need network-level mitigation from your VPS provider or upstream network. Ask the provider what is covered, preserve required SSH/control access and test any firewall or limit changes.

## 5. Confirm health and sign in privately

```
sudo systemctl is-active proxvn
sudo systemctl status proxvn --no-pager
curl --fail --show-error http://127.0.0.1:8881/health
sudo journalctl -u proxvn -n 80 --no-pager
sudo ss -lntup | grep -E ':(80|443|8880|8881|8882)\b'
curl --fail --show-error --head https://example.com/
curl --fail --show-error --head https://example.com/console/
```

The service should be active, health should return JSON status ok and version 9.x, and both public HTTPS checks should succeed without disabling certificate verification. Open the Console in your browser, then retrieve the initial password in your private SSH session:

$` sudo cat /var/lib/proxvn/admin-password.txt `

Change the initial password after signing in. The bootstrap file is not a password manager and does not update when you change the account password. Keep it, the environment and all API keys out of screenshots and public support logs.

## 6. Verify the control certificate before the first client connection

The client also needs to recognize the correct server. A **control certificate pin** is a public hash of that server’s connection certificate. You compare it through a trusted channel, then the client checks it when connecting. This protects the client-server connection independently of the browser’s website certificate. The hash can be shared; the certificate’s private key must stay private.

**VPS:**

```
sudo openssl x509 -in /var/lib/proxvn/server.crt -outform DER \
  | sha256sum | awk '{print $1}'
```

Copy this public 64-character hash through your trusted SSH session. This is the certificate on port 8882 (` server.crt `), not ` wildcard.crt ` used by the browser. The hash is over DER certificate bytes; an OpenSSL fingerprint with colon separators is a different display format. Keep the matching certificate/private key in your backup so clients retain the same server identity after a reinstall.

## 7. Create a tiny local website and open a tunnel

**Local Linux/macOS terminal A:** Python 3 serves the current folder, so choose a folder containing only files you intend to share. This binds to loopback and does not expose your home directory accidentally.

```
mkdir -p proxvn-demo
cd proxvn-demo
python3 -m http.server 3000 --bind 127.0.0.1
```

**Local terminal B:**

```
curl --fail http://127.0.0.1:3000
curl -fsSLo install-proxvn.sh https://proxvn.io.vn/install.sh
PROXVN_BASE=https://proxvn.io.vn sh install-proxvn.sh
proxvn version
PIN=PASTE_THE_VERIFIED_64_HEX_CHARACTER_HASH
proxvn --server tunnel.example.com:8882 --insecure=false --token= --cert-pin "$PIN" http 3000
```

For this first guest test, ` --token= ` prevents an unrelated saved or environment API key from being sent to the new server. ` --insecure=false ` overrides any saved insecure setting so certificate pin verification remains active.

Keep both terminals running. Copy the actual HTTPS URL printed by the client and open it from a phone on mobile data or another network. You should see the same demo directory listing as localhost. The subdomain is assigned dynamically; do not invent one and assume it exists. Stop the tunnel with Ctrl+C when finished. For Windows, Android, file sharing and running a persistent client, continue with the [complete client tutorial](https://proxvn.io.vn/blog/run-client).

## 8. Attach the tunnel to your own account

In your own Console, create/use the account that should own the tunnel and copy its API key from Account. Login only saves that key to the local user configuration; it does not choose a server or verify the key with an API call. Use this order:

```
proxvn login YOUR_OWN_SERVER_API_KEY
proxvn --server tunnel.example.com:8882 --insecure=false --cert-pin "$PIN" http 3000 --subdomain myapp
```

This authenticated example does not set ` --token= `: it needs your saved own-server token. An existing ` PROXVN_TOKEN ` or a token in a selected/local JSON file can override the user configuration written by login. Remove an unrelated environment value or choose the correct configuration first; the [client configuration reference](https://proxvn.io.vn/docs/client#config) explains precedence.

Reserve ` myapp ` in your Console for durable ownership. Use the API key issued by this server, not a key from the official service. Do not append ` --server ` to the login subcommand. You can merge server, cert_pin and token into an existing JSON configuration later; the [reference shows the fields](https://proxvn.io.vn/docs/self-host#client) without overwriting your saved settings.

## 9. Verify TCP and UDP when you actually need them

**Local:**

```
proxvn --server tunnel.example.com:8882 --insecure=false --token= --cert-pin "$PIN" tcp 22
proxvn --server tunnel.example.com:8882 --insecure=false --token= --cert-pin "$PIN" udp 19132
```

Run one at a time or in separate terminals. These examples require a real SSH server on local TCP 22 or a UDP game server on 19132; ProxVN does not create those services. From another network connect to the actual host:port printed by the client using the matching protocol. A successful control connection does not prove the assigned public port passes traffic. UDP additionally needs 8882/udp, the assigned public UDP port and clocks synchronized within 30 seconds.

## 10. Add email only after the core path works

**VPS:** edit ` /etc/proxvn/proxvn.env ` with ` sudoedit `, add your relay values below and keep the file private. These are placeholders, not working credentials.

```
SMTP_ENABLED=true
SMTP_HOST=smtp.example.net
SMTP_PORT=587
SMTP_USER=operator@example.com
SMTP_PASSWORD=REPLACE_WITH_RELAY_PASSWORD
SMTP_FROM=operator@example.com
SMTP_FROM_NAME=ProxVN
SMTP_DAILY_LIMIT=450
```

$` sudo systemctl restart proxvn `

Port 587 requires STARTTLS in this mailer; 465 uses implicit TLS. In Console → Website settings → Email & security, send a test to yourself and check Inbox/Spam. Do not enable required email verification until registration/recovery links work end to end. SMTP acceptance is different from observing Inbox delivery.

## 11. Make a restorable snapshot before calling it done

**VPS:** this briefly stops the service, archives the matching application/configuration/complete state (including any SQLite WAL files), and starts it again even if creating the archive fails.

```
backup_dir="/var/backups/proxvn/manual-$(date -u +%Y%m%dT%H%M%SZ)"
sudo install -d -m 0700 "$backup_dir"
(
  set -eu
  trap 'sudo systemctl start proxvn' EXIT
  sudo systemctl stop proxvn
  sudo tar -C / -czf "$backup_dir/proxvn-host.tar.gz" \
    opt/proxvn etc/proxvn var/lib/proxvn \
    etc/systemd/system/proxvn.service
  sudo chmod 0600 "$backup_dir/proxvn-host.tar.gz"
  sudo tar -tzf "$backup_dir/proxvn-host.tar.gz" >/dev/null
)
sudo systemctl is-active proxvn
sudo sha256sum "$backup_dir/proxvn-host.tar.gz"
```

Copy that private archive off the VPS and record its checksum. It contains credentials and keys: do not put it in the website or Git repository. Automatic daily database backups are useful but are not a substitute for the complete snapshot. The [restore procedure](https://proxvn.io.vn/docs/self-host#backup) moves the current state aside so restored databases are never mixed with stale WAL/SHM files.

## 12. Know your next restart and upgrade commands

```
sudoedit /etc/proxvn/proxvn.env
sudo systemctl restart proxvn
sudo journalctl -u proxvn -f
```

For an upgrade, take a new full snapshot first, read the release notes, then re-run the installer with the official source. Existing environment/data are preserved; the application and generated unit are updated. Changing installer flags later does not rewrite the saved domain/port configuration. Upgrade all clients alongside a major protocol change; 9.x requires 9.x peers and old Console sessions may need to sign in again.

```
curl -fsSLo install-server.sh https://proxvn.io.vn/install-server.sh
sudo bash install-server.sh --source https://proxvn.io.vn
curl --fail --show-error http://127.0.0.1:8881/health
curl --fail --show-error --head https://example.com/
```

Before inviting users, confirm the real HTTPS link works from another network, the control certificate pin is verified, your account owns its intended name, the required public ports pass actual traffic, and the backup can be restored. When a check fails, use the [layer-by-layer troubleshooting table](https://proxvn.io.vn/docs/self-host#troubleshoot) rather than weakening TLS verification or exposing the private API.
