Wildcard Subdomains in Namecheap DNS for Dynamic Web Apps

by Fahim

Manually creating DNS records every time a user signs up for your multi-tenant app is a fast path to broken deployments and rate limits. The cleaner fix is simple: drop a wildcard DNS record into Namecheap once, and let your reverse proxy handle the dynamic subdomains automatically.

Wildcard Subdomains in Namecheap DNS for Dynamic Web Apps
Wildcard Subdomains in Namecheap DNS for Dynamic Web Apps

How Wildcard Subdomains Work Behind the Scenes

A wildcard DNS record is just a catch-all for unassigned subdomains. When a resolver looks up acme.example.com, it first checks if an explicit A or CNAME record exists for acme. If nothing turns up, it falls back to your asterisk (*) rule.

That means you can spin up client workspaces, preview environments, or user profile domains on the fly without touching your DNS registrar again. Routing moves entirely into your proxy and application code. If you’ve already spent time pointing a root domain with ALIAS records in Namecheap, the dashboard layout will look familiar.

Keep the RFC 1034 DNS specifications in mind: a wildcard only matches one label level. *.example.com matches tenant.example.com and dashboard.example.com, but it won’t catch nested subdomains like api.tenant.example.com.

Step 1: Add the Wildcard Record in Namecheap Advanced DNS

First, head into your Namecheap dashboard. Make sure your domain is set to Namecheap BasicDNS or Namecheap Web Hosting DNS. If you’re using custom external nameservers, changes here won’t do anything.

  1. Log in to Namecheap.
  2. Click Domain List on the left, then hit Manage next to your domain.
  3. Switch to the Advanced DNS tab up top.
  4. Find the Host Records table and click Add New Record.

Pick the record type based on your stack. If you’re pointing directly to a VPS with a static public IP, use an A Record. If you’re behind an ALB, PaaS endpoint, or CDN, pick a CNAME Record.

Fill out the fields like this:

  • Type: A Record (or CNAME Record)
  • Host: *
  • Value: 198.51.100.42 (your server’s IP, or your canonical hostname for a CNAME)
  • TTL: Automatic (or drop it to 1 min while testing so you don’t wait around)

Click the green checkmark to save. Namecheap changes usually kick in within 3 to 15 minutes, though local resolver caches can make it feel longer.

Verifying DNS Resolution from the Terminal

Don’t test this in a browser. Browser caching and HSTS rules will lie to you. Use your terminal and query a public resolver directly.

Query Google (8.8.8.8) or Cloudflare (1.1.1.1) using dig to see if a random string subdomain lands on your IP:

dig +short randomworkspace982.example.com @1.1.1.1

Here’s what came back when I verified mine:

# Output:
198.51.100.42

If you prefer nslookup, run this instead:

nslookup test-tenant.example.com 8.8.8.8

If you get back empty results or a timeout, check your Namecheap table for conflicting records. Explicit records always take priority over the wildcard.

Step 2: Route Wildcard Traffic in Nginx (Reverse Proxy Setup)

Namecheap will now send any arbitrary subdomain to your box, but Nginx still needs to accept those host headers. A standard server block with a hardcoded domain will just reject or drop unlisted subdomains.

As covered in the Nginx server_names documentation, Nginx supports wildcard patterns natively. Here’s a clean config that accepts wildcard subdomains and proxies them back to an app listening on port 3000.

sudo nano /etc/nginx/sites-available/wildcard-app.conf

Drop this configuration block into your site file:

server { listen 80; listen [::]:80; server_name *.example.com example.com; location / { proxy_pass http://127.0.0.1:3000; 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-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_cache_bypass $http_upgrade; }
}

Test the syntax and reload Nginx:

sudo ln -s /etc/nginx/sites-available/wildcard-app.conf /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

The key piece here is proxy_set_header Host $host;. It ensures your backend gets the actual subdomain the user typed into their browser.

Step 3: Extract the Tenant Subdomain in Node.js

Down at the application layer, you need to pull that host header apart, grab the subdomain, and query your database for that tenant.

Here’s a straightforward Express middleware snippet that strips out port numbers, ignores the root domain, and isolates the subdomain cleanly:

const express = require('express');
const app = express(); function tenantMiddleware(req, res, next) { const host = req.headers.host || ''; const cleanHost = host.split(':')[0]; // Strip port if present const baseDomain = 'example.com'; if (cleanHost === baseDomain || cleanHost === `www.${baseDomain}`) { req.tenantId = null; return next(); } if (cleanHost.endsWith(`.${baseDomain}`)) { const parts = cleanHost.replace(`.${baseDomain}`, '').split('.'); req.tenantId = parts[parts.length - 1]; // Grabs tenant slug return next(); } req.tenantId = null; next();
} app.use(tenantMiddleware); app.get('/', (req, res) => { if (!req.tenantId) { return res.send('Welcome to the Main Landing Page'); } res.send(`Serving dynamic workspace for tenant: ${req.tenantId}`);
}); app.listen(3000, () => { console.log('Server running on port 3000');
});

If you’re running a CMS fleet rather than a Node app, the underlying logic is identical to how you set up WordPress Multisite with subdomains, letting the platform parse host headers internally.

Step 4: Issue a Wildcard SSL Certificate with Certbot (DNS-01 Challenge)

Here’s where people usually get stuck: standard HTTP-01 challenges (the automatic webroot checks Certbot uses) do not work for wildcard domains. You have to use a Let’s Encrypt DNS-01 challenge.

The DNS-01 flow requires adding an _acme-challenge TXT record in Namecheap to prove you actually control the root zone.

sudo certbot certonly --manual --preferred-challenges=dns  -d example.com  -d "*.example.com"

Certbot will pause and hand you a verification token:

Please deploy a DNS TXT record under the name:
_acme-challenge.example.com
with the following value:
4uW9dZ9XyR3M0P1qKlJt887BvNaSdfLkj90234LmNOP

Leave that terminal window sitting there. Open Namecheap in your browser:

  1. Under Advanced DNS, click Add New Record.
  2. Select TXT Record.
  3. Set the Host to _acme-challenge (Namecheap appends your domain automatically).
  4. Paste that long challenge string into the Value field.
  5. Set the TTL to 1 min and save it.

Before hitting Enter in Certbot, open a fresh terminal tab and make sure the TXT record actually resolves publicly:

dig +short TXT _acme-challenge.example.com @1.1.1.1

Once you see the token string come back, switch back to Certbot and press Enter. If you run into weird handshake issues later on, take a look at our walkthrough on fixing SSL certificate errors on a subdomain to verify your intermediate chain.

Once Certbot drops the cert files into /etc/letsencrypt/live/example.com/, update your Nginx config to point to them and reload the service.

Gotcha: Namecheap DNS Propagation and Record Precedence

Here’s a bug that cost me an hour: I had an old CNAME entry sitting in my records for billing. When I hit billing.example.com, it kept routing to a dead payment page instead of hitting my Node app, while every other subdomain worked great.

In DNS resolution, explicit records always beat wildcard records. If your Namecheap table contains any of these:

  • An explicit A record for billing
  • A leftover CNAME for mail or blog
  • Default parking page records left behind by Namecheap

The resolver stops on that exact match and completely ignores your * rule. Audit your entire Host Records table and delete anything stale that overlaps with subdomains you want to handle dynamically.

If you’re using a paid commercial cert instead of Certbot, you can also verify a Namecheap SSL certificate with DNS CNAME records without touching or breaking your wildcard records.

Troubleshooting Common Wildcard DNS Pitfalls

If things aren’t resolving properly, run down this list:

  • Multi-Level Subdomains Failing: dev.team.example.com won’t match a single * record. You need an explicit *.* record in Namecheap for two levels down (and keep in mind standard SSL certs won’t cover nested wildcards).
  • Nginx 404 or Default Welcome Page: Double-check that your server_name line includes *.example.com. Without it, requests land on whatever default site block is enabled.
  • Mixed Content Warnings: If your assets load from absolute non-HTTPS URLs or don’t account for dynamic tenant subdomains, browsers will block them. Stick to relative paths like /assets/app.js.
  • CORS Issues: If client-side JavaScript on tenant1.example.com calls an API on api.example.com, your backend needs to send an Access-Control-Allow-Origin header matching that tenant origin explicitly.

Frequently Asked Questions

Can I point a wildcard subdomain to an external service using a CNAME in Namecheap?

Yes. Set Type to CNAME Record, put * in the Host field, and enter your target (like domains.customapp.io) into the Value field. Just don’t leave an A record with * in the same table, or they’ll collide.

Does a Namecheap wildcard record cover the root domain?

No. The * wildcard only matches strings in front of your domain. To handle example.com, you still need an explicit @ host record pointing to your server.

How do I automate Certbot renewals for wildcard certificates?

Because wildcard certificates need DNS-01 validation, standard Certbot renewal cron jobs will fail. You have to hook Certbot up to an API plugin (or use RFC 2136 dynamic updates) so it can create and clean up the _acme-challenge TXT record automatically during renewal.

Will a wildcard subdomain slow down my DNS response times?

Not at all. Resolvers look up wildcard rules just as fast as static A records. Responses typically clock in between 10ms and 50ms depending on how close the user is to the resolver.

Next Steps for Multi-Tenant Deployments

Once Namecheap routes all your subdomains through cleanly, your app is ready to provision accounts without any manual DNS tweaks. Just make sure your production server has proper memory limits, swap space, and process monitoring in place so one runaway tenant can’t drag down the whole instance.

all_in_one_marketing_tool