Securing Nginx Reverse Proxy Subdomains with Certbot
What You’ll Need
- Hetzner VPS or Contabo VPS running Ubuntu 22.04 or Debian 12
- DigitalOcean as an alternative cloud infrastructure provider
- Namecheap for managing registered domain names and DNS records
- n8n Cloud or self-hosted services running locally on backend ports
Table of Contents
- Setting Up Your Server and DNS Architecture
- Configuring Nginx Reverse Proxy Server Blocks
- Provisioning SSL Certificates with Certbot
- Automating Certificate Renewal and Hardening TLS Security
- Getting Started
Setting Up Your Server and DNS Architecture
Routing traffic across multiple microservices or backend applications requires a clean, maintainable reverse proxy layer. When hosting services on a virtual private server from Hetzner VPS, managing multiple subdomains under a single public IP address is standard practice. Nginx acts as the traffic controller, handling incoming requests on port 80 and port 443, then proxying them to internal ports such as 5678, 8080, or 3000.
Before writing web server configurations or generating SSL certificates, you must configure your DNS A records properly. Log into your domain registrar, such as Namecheap, and navigate to your Advanced DNS management panel.
Create DNS A records pointing your target subdomains to your server’s static IPv4 address:
Type: A Record | Host: app | Value: 192.0.2.45 | TTL: Automatic
Type: A Record | Host: hooks | Value: 192.0.2.45 | TTL: Automatic
Type: A Record | Host: api | Value: 192.0.2.45 | TTL: Automatic
If you plan to use a wildcard setup for dynamic subdomains, you can add a single wildcard A record instead:
Type: A Record | Host: * | Value: 192.0.2.45 | TTL: Automatic
Verify that the DNS records have propagated using the dig command from your local terminal:
dig +short app.yourdomain.com
dig +short hooks.yourdomain.com
Once both commands resolve to your server IP address, SSH into your server to update system packages and install Nginx alongside Certbot:
sudo apt-get update
sudo apt-get install -y nginx certbot python3-certbot-nginx
Verify that Nginx is running and enabled on system startup:
sudo systemctl status nginx
sudo systemctl enable nginx
Ensure your server firewall allows incoming HTTP and HTTPS connections:
sudo ufw allow 'Nginx Full'
sudo ufw enable
sudo ufw status
With the base software installed and firewall ports open, you can begin configuring Nginx server blocks for each backend service.
Configuring Nginx Reverse Proxy Server Blocks
Nginx organizes site configurations inside the /etc/nginx/sites-available/ directory. To keep your deployment modular, create individual configuration files for each subdomain rather than placing all declarations inside /etc/nginx/nginx.conf.
We will configure two subdomains: app.yourdomain.com for a main user interface and hooks.yourdomain.com for incoming webhooks. When building resilient webhooks, pairing your reverse proxy with techniques detailed in our guide on Implementing Circuit Breakers for Outbound Webhook Delivery ensures system stability during high traffic spikes.
Create the server block configuration for app.yourdomain.com:
sudo nano /etc/nginx/sites-available/app.yourdomain.com.conf
Paste the following complete HTTP configuration into the file:
server {
listen 80;
listen [::]:80;
server_name app.yourdomain.com;
access_log /var/log/nginx/app.yourdomain.com.access.log;
error_log /var/log/nginx/app.yourdomain.com.error.log;
location /.well-known/acme-challenge/ {
root /var/www/html;
}
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_buffering off;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
}
Next, create the configuration for hooks.yourdomain.com:
sudo nano /etc/nginx/sites-available/hooks.yourdomain.com.conf
Paste the following complete configuration for the webhook handler service:
server {
listen 80;
listen [::]:80;
server_name hooks.yourdomain.com;
access_log /var/log/nginx/hooks.yourdomain.com.access.log;
error_log /var/log/nginx/hooks.yourdomain.com.error.log;
location /.well-known/acme-challenge/ {
root /var/www/html;
}
location / {
proxy_pass http://127.0.0.1:5678;
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;
client_max_body_size 50M;
}
}
Enable both site configurations by creating symbolic links in the /etc/nginx/sites-enabled/ directory:
sudo ln -s /etc/nginx/sites-available/app.yourdomain.com.conf /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/hooks.yourdomain.com.conf /etc/nginx/sites-enabled/
Remove the default Nginx configuration link if it is still present to avoid host default fallback issues:
sudo rm -f /etc/nginx/sites-enabled/default
Test the Nginx configuration syntax for any errors:
sudo nginx -t
If the terminal displays syntax is ok and test is successful, reload Nginx:
sudo systemctl reload nginx
💡 Fast-Track Your Project: Don’t want to configure this yourself? I build custom n8n pipelines and bots. Message me with code SYS3-HUGO.
Provisioning SSL Certificates with Certbot
With HTTP server blocks functioning, Let’s Encrypt certificates can be requested via Certbot using the Nginx plugin. Certbot will read your enabled server blocks, communicate with Let’s Encrypt servers to execute an HTTP-01 challenge, retrieve signed certificates, and update your configuration files automatically.
Execute Certbot for both subdomains in a single command:
sudo certbot --nginx -d app.yourdomain.com -d hooks.yourdomain.com --redirect
During execution, Certbot will prompt you to provide an administrative email address for renewal notifications and accept the Let’s Encrypt Terms of Service. Because we passed the --redirect flag, Certbot automatically modifies your HTTP server blocks to enforce HTTPS redirects.
If you prefer to keep multi-tenant applications distinct, managing subdomains at the proxy level pairs naturally with database-level isolation. Read our tutorial on Configuring PostgreSQL Row Level Security for Multitenancy to secure tenant data downstream.
Let’s inspect how Certbot updates your configuration file. Open /etc/nginx/sites-available/app.yourdomain.com.conf:
sudo cat /etc/nginx/sites-available/app.yourdomain.com.conf
Certbot expands the file to look like this:
server {
server_name app.yourdomain.com;
access_log /var/log/nginx/app.yourdomain.com.access.log;
error_log /var/log/nginx/app.yourdomain.com.error.log;
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_buffering off;
proxy_read_timeout 86400s;
proxy_send_timeout 86400s;
}
listen [::]:443 ssl ipv6only=on;
listen 443 ssl;
ssl_certificate /etc/letsencrypt/live/app.yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/app.yourdomain.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
}
server {
if ($host = app.yourdomain.com) {
return 301 https://$host$request_uri;
}
listen 80;
listen [::]:80;
server_name app.yourdomain.com;
return 404;
}
If you require a wildcard SSL certificate covering *.yourdomain.com instead of individual domain flags, you must perform a DNS-01 challenge instead of HTTP-01. A DNS-01 challenge requires proof of domain ownership by placing a TXT record into your DNS settings.
To generate a wildcard certificate using Certbot manually:
sudo certbot certonly --manual --preferred-challenges dns -d "*.yourdomain.com" -d "yourdomain.com"
Certbot will output specific TXT record keys:
Please deploy a DNS TXT record under the name
_acme-challenge.yourdomain.com with the following value:
c8zW9xL0pQ1mR2sT3uV4wX5yZ6aB7cD8eF9gH0iJ1kL
Before continuing, verify the record is deployed.
Open a second terminal window and verify that the TXT record is visible globally before pressing Enter in your Certbot window:
dig +short TXT _acme-challenge.yourdomain.com
Once confirmed, hit Enter. Certbot saves the wildcard certificate files into /etc/letsencrypt/live/yourdomain.com/. You can then reference these unified files across all your Nginx subdomain blocks manually.
Automating Certificate Renewal and Hardening TLS Security
Let’s Encrypt certificates are valid for 90 days. Certbot automatically registers a systemd timer or cron job upon installation to handle renewals before expiration.
Check the status of the Certbot systemd timer:
sudo systemctl status certbot.timer
To test the automated renewal process without altering actual production certificates, run a dry run simulation:
sudo certbot renew --dry-run
To ensure Nginx reloads its configuration smoothly whenever a certificate is renewed, configure a deployment hook inside the Certbot configuration directory. Create a post-renewal script:
sudo nano /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh
Paste the following shell script:
#!/bin/sh
systemctl reload nginx
Make the script executable:
sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh
Now, every time Certbot successfully renews an SSL certificate, systemd automatically executes this script to reload Nginx without dropping active connection pools.
To maximize security scores on tools like SSL Labs, create a dedicated security configuration file that enforces TLS 1.2 and TLS 1.3, strong cipher suites, HTTP Strict Transport Security (HSTS), and OCSP Stapling.
Create the common SSL parameters file:
sudo nano /etc/nginx/conf.d/ssl-params.conf
Paste the complete security parameters configuration:
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers on;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;
ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 5s;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;
If your infrastructure interfaces with external language models or automation layers, secure endpoints are essential. For an example of how SSL-secured API endpoints plug into enterprise workflows, explore our guide on Connecting Claude AI to workflow systems tutorial.
Test your enhanced security configuration:
sudo nginx -t
Reload Nginx to activate the security headers and optimized TLS settings:
sudo systemctl reload nginx
Check the active SSL headers using curl:
curl -I https://app.yourdomain.com
The output will confirm that HTTPS is enforced with standard security headers:
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 24 Feb 2025 12:00:00 GMT
Content-Type: text/html
Connection: keep-alive
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
X-Content-Type-Options: nosniff
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Getting Started
Securing subdomains with Nginx and Certbot gives your infrastructure enterprise grade encryption, automated maintenance, and maximum client throughput. By provisioning virtual servers on cloud platforms like Hetzner VPS or Contabo VPS and configuring your domains on Namecheap, you maintain total control over your backend architecture.
Verify your setup by ensuring:
- DNS A records resolve correctly to your server IP.
- Nginx server blocks isolate each internal port mapping accurately.
- Certbot automated renewal dry runs complete without error.
- Security headers like HSTS and modern TLS versions are active.
Outsource Your Automation
Don’t have time? I build production n8n workflows, WhatsApp bots, and fully automated YouTube Shorts pipelines. Hire me on Fiverr, mention SYS3-HUGO for priority. Or DM at chasebot.online.
Want to automate this yourself?
Start with n8n Cloud (free tier available) or self-host on a Hetzner VPS for full control.
Want this engine running on your own VPS?
This blog publishes itself — daily, unattended, on free API tiers. The full engine, Hugo theme, and setup guide are available as System 3.
Get System 3