NewCode CLOUD — 20% off your first month on all cloud VPSClaim

HTTPS Certificate Management on Hong Kong VPS: Let’s Encrypt and Wildcard (2026)

· 3 min read

Every Hong Kong VPS serving web traffic needs valid HTTPS certificates. Let’s Encrypt provides free, browser-trusted certificates; Certbot automates renewal; and DNS-01 challenge validation enables wildcard certificates for all subdomains without exposing port 80 — essential for internal-only services behind Nginx.


Step 1: Install Certbot

<code">apt update && apt install -y certbot python3-certbot-nginx python3-certbot-dns-cloudflare

certbot --version

Step 2: Single Domain Certificate (HTTP-01)

<code"># Simplest method — requires port 80 open
certbot --nginx -d yourdomain.com -d www.yourdomain.com \
  --non-interactive --agree-tos --email admin@yourdomain.com

# Test auto-renewal
certbot renew --dry-run

# Certificates stored at:
ls /etc/letsencrypt/live/yourdomain.com/
# cert.pem fullchain.pem privkey.pem chain.pem

Step 3: Wildcard Certificate (DNS-01 with Cloudflare)

<code"># Wildcard *.yourdomain.com covers ALL subdomains
# Requires DNS-01 challenge — proves domain ownership via DNS TXT record
# No port 80 needed (works for internal services too)

# Create Cloudflare API token:
# Cloudflare → My Profile → API Tokens → Create Token
# Template: Edit zone DNS → select your domain

mkdir -p /root/.secrets
cat > /root/.secrets/cloudflare.ini << 'EOF'
dns_cloudflare_api_token = YOUR_CLOUDFLARE_API_TOKEN
EOF
chmod 600 /root/.secrets/cloudflare.ini

# Issue wildcard certificate
certbot certonly \
  --dns-cloudflare \
  --dns-cloudflare-credentials /root/.secrets/cloudflare.ini \
  -d yourdomain.com \
  -d "*.yourdomain.com" \
  --non-interactive \
  --agree-tos \
  --email admin@yourdomain.com

# Now ANY subdomain is covered:
# api.yourdomain.com, cms.yourdomain.com, auth.yourdomain.com, etc.

Step 4: Configure Nginx for Multiple Subdomains

<code"># All subdomains share ONE wildcard certificate
cat > /etc/nginx/snippets/ssl-yourdomain.conf << 'EOF'
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;

# Modern SSL settings
ssl_protocols TLSv1.2 TLSv1.3;
ssl_prefer_server_ciphers off;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d;
ssl_session_tickets off;

# HSTS (enable only when you're sure — hard to undo)
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
EOF

# Each virtual host just includes the snippet:
server {
    listen 443 ssl http2;
    server_name api.yourdomain.com;
    include /etc/nginx/snippets/ssl-yourdomain.conf;
    location / { proxy_pass http://127.0.0.1:3000; }
}

server {
    listen 443 ssl http2;
    server_name cms.yourdomain.com;
    include /etc/nginx/snippets/ssl-yourdomain.conf;
    location / { proxy_pass http://127.0.0.1:1337; }
}

Step 5: Auto-Renewal and Monitoring

<code"># Certbot installs a systemd timer automatically
systemctl list-timers | grep certbot
# certbot.timer   12h    certbot.service

# Test renewal (safe — doesn't actually renew if >30 days remaining)
certbot renew --dry-run

# Hook to reload Nginx after successful renewal
mkdir -p /etc/letsencrypt/renewal-hooks/deploy
cat > /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh << 'EOF' #!/bin/bash nginx -t && systemctl reload nginx EOF chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh # Monitor expiry (alert 14 days before expiry) cat > /opt/check-ssl.sh << 'EOF' #!/bin/bash DOMAIN=yourdomain.com EXPIRY=$(echo | openssl s_client -connect $DOMAIN:443 -servername $DOMAIN 2>/dev/null \
  | openssl x509 -noout -enddate | cut -d= -f2)
EXPIRY_EPOCH=$(date -d "$EXPIRY" +%s)
NOW_EPOCH=$(date +%s)
DAYS=$(( (EXPIRY_EPOCH - NOW_EPOCH) / 86400 ))

if [ $DAYS -lt 14 ]; then
  echo "SSL ALERT: $DOMAIN expires in $DAYS days" | \
    mail -s "SSL Expiry Warning" admin@yourdomain.com
fi
EOF
chmod +x /opt/check-ssl.sh
crontab -l | { cat; echo "0 9 * * * /opt/check-ssl.sh"; } | crontab -

Step 6: Certificate for Internal Services (Port 443 Closed)

<code"># For internal services not accessible on port 80/443 from internet
# DNS-01 challenge works without any open ports

# Issue cert for internal monitoring dashboard
certbot certonly \
  --dns-cloudflare \
  --dns-cloudflare-credentials /root/.secrets/cloudflare.ini \
  -d grafana.yourdomain.com \
  --non-interactive --agree-tos --email admin@yourdomain.com

# Grafana behind Nginx with IP restriction:
server {
    listen 443 ssl http2;
    server_name grafana.yourdomain.com;
    ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
    allow YOUR_OFFICE_IP;
    deny all;
    location / { proxy_pass http://127.0.0.1:3000; }
}

SSL Grade Check

<code"># Check your SSL configuration grade
# https://www.ssllabs.com/ssltest/analyze.html?d=yourdomain.com

# Target: A or A+ rating
# A+ requires: TLS 1.3, HSTS, no weak ciphers, valid chain

# Quick local check:
openssl s_client -connect yourdomain.com:443 -servername yourdomain.com < /dev/null 2>/dev/null \
  | openssl x509 -noout -dates -subject

Conclusion

HTTPS certificate management on a Hong Kong VPS is fully automated with Certbot and Cloudflare DNS-01 validation — wildcard certificates cover all subdomains from one renewal cycle, renewal hooks reload Nginx automatically, and expiry monitoring alerts before certificates lapse. The DNS-01 approach works for internal services that don’t expose port 80, making it the preferred method for VPS deployments where multiple apps share one domain with many subdomains.

Secure every subdomain: Browse Server.HK Hong Kong VPS plans — wildcard Let’s Encrypt certificates work on any plan; configure once and all subdomains are covered.

Related articles

More in VPS & ServersServer setup guides