natbox.io

Blog / Wildcard subdomains

Wildcard subdomains on a NAT VPS: a subdomain for every customer

2 December 2026 · Guide · By Mohammad AlSaraf

On a NAT VPS your server shares its IPv4 address with other servers, so ports 80 and 443 can't simply be yours. We route them by name instead: when a visitor asks for example.com, the request goes to the server that linked that name. Until now that meant linking every name on its own. If you run an app that gives each of its customers a subdomain, such as alice.myapp.com and bob.myapp.com, you had to add each one by hand and you ran into your plan's domain limit.

Since 1 December you can link a wildcard instead: *.myapp.com. Every subdomain of myapp.com then reaches your server, new ones included, and the wildcard counts as one domain. It works on all paid plans, from Nano at $1 a month. As far as we know, few NAT VPS hosts offer this on a shared IPv4 address.

About 15 minutes. You need a paid natbox server, a domain whose DNS you control, and nginx (the same idea works with Caddy or Apache).

When a wildcard helps

How a request finds your server

Diagram: a request for alice.myapp.test is first checked against names linked on their own, which always win, then against wildcards like *.myapp.test, where the longest match wins, and then reaches your server on ports 80 and 443 with HTTPS still encrypted. With no match the visitor sees 'This domain is not hosted on natbox.io'; the bare myapp.test is not covered by the wildcard.

Open your server in the client area, go to the Domains tab and add *.myapp.com. The tab then shows two records to create where your DNS is managed:

TypeNameValue
A*.myapp.comyour server's shared IPv4 address (shown on the tab)
TXT_natbox.myapp.comthe natbox-verify=… code shown on the tab

Then press Verify. We look for the TXT record, and we check the wildcard itself by asking public DNS for a random name under myapp.com: it has to point only to your server's IPv4 address. New records can take a few minutes, sometimes up to an hour, to show up. Optionally add an AAAA record for *.myapp.com pointing to your server's IPv6 address, so IPv6 visitors reach you directly.

2. One nginx block for every customer

On your server, one server block can answer for every subdomain. A regular expression in server_name captures the first part of the name, and nginx uses it to pick that customer's folder. Here it is on our demo server, for the test name myapp.test:

Terminal: the file /etc/nginx/sites-available/myapp with one server block, listen 80, server_name ~^(?<customer>[a-z0-9-]+)\.myapp\.test$, root /srv/customers/$customer and try_files.

With that, adding a customer is creating a folder: nothing to change in nginx, and nothing in the client area. Here is the demo from the outside, after linking *.myapp.test. The --resolve option stands in for DNS, because .test names don't exist on the internet:

Terminal: curl requests to alice.myapp.test and bob.myapp.test return 'Hello from alice's site' and 'Hello from bob's site'; carol.myapp.test returns HTTP 404 from nginx because she has no folder; the bare myapp.test returns 'This domain is not hosted on natbox.io'.

Alice and bob each get their own site. Carol has no folder yet, so your nginx answers 404: the request did reach your server. The bare myapp.test is not covered by the wildcard, so our front door answers instead.

If each customer runs their own app instead of static files, map the name to a port and proxy to it:

map $customer $backend {
    alice 127.0.0.1:3001;
    bob   127.0.0.1:3002;
}
server {
    listen 80;
    server_name ~^(?<customer>[a-z0-9-]+)\.myapp\.com$;
    location / {
        if ($backend = "") { return 404; }
        proxy_pass http://$backend;
        proxy_set_header Host $host;
    }
}

3. HTTPS for every subdomain

Let's Encrypt only issues wildcard certificates after a DNS check: you prove control of the domain with a TXT record. The quickest way to try it is by hand:

certbot certonly --manual --preferred-challenges dns \
  -d myapp.com -d '*.myapp.com'

For renewals without manual steps, use the certbot DNS plugin for your DNS provider. With Cloudflare, for example: apt install python3-certbot-dns-cloudflare, put an API token with DNS edit rights in /root/.secrets/cloudflare.ini (chmod 600), then:

certbot certonly --dns-cloudflare --dns-cloudflare-credentials /root/.secrets/cloudflare.ini \
  -d myapp.com -d '*.myapp.com'

Then add listen 443 ssl; and the ssl_certificate lines to the same server block. Because port 80 also reaches your server, the normal HTTP check (certbot --nginx -d alice.myapp.com) works too, one name at a time. That is fine for a handful of customers; the wildcard certificate is easier once there are many.

Another way: your own IPv6 behind Cloudflare

Every natbox server also has its own block of IPv6 addresses, open on every port. If your domain is on Cloudflare, a proxied (orange cloud) wildcard AAAA record pointing to your server's IPv6 address works without linking anything: Cloudflare accepts visitors over IPv4 and IPv6 and connects to your server over IPv6. Its free certificate covers one level of wildcard (*.myapp.com), not two (*.agents.myapp.com). Linking the wildcard on natbox, as above, has no such limit and needs no Cloudflare.

Good to know

Building something with a subdomain per customer on natbox? We'd like to hear about it, and it could be a good entry for our "Write about natbox" contest, open until 15 December.

Get new tutorials in Telegram. Follow @natboxio: every new post, plus short server tips.

More from the blog: November 2026 uptime report: 21 problems, and what caused them, Our first measurement report: 33 studies from a $1 VPS host, Your natbox disk holds about twice what it says. RSS feed.