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

SSL/TLS on Hong Kong VPS: Let’s Encrypt, Wildcard Certs & Best Practices (2026)

· 5 min read

Every production website and API on a Hong Kong VPS needs HTTPS — for security, for SEO, and because modern browsers flag HTTP sites as “Not Secure.” Let’s Encrypt provides free, automatically renewing SSL certificates. This guide covers standard domain certificates, wildcard certificates for subdomains, HTTP/2 enablement, HSTS, and TLS configuration that passes security audits.


Step 1: Install Certbot

apt update && apt install -y certbot python3-certbot-nginx

# Verify certbot can contact Let's Encrypt
certbot --version

Step 2: Issue a Standard Certificate

# Nginx plugin — automatically configures Nginx
certbot --nginx -d yourdomain.com -d www.yourdomain.com

# Or standalone mode (temporarily stops Nginx to use port 80)
systemctl stop nginx
certbot certonly --standalone -d yourdomain.com -d www.yourdomain.com
systemctl start nginx

Certificates are stored at:

  • Certificate: /etc/letsencrypt/live/yourdomain.com/fullchain.pem
  • Private key: /etc/letsencrypt/live/yourdomain.com/privkey.pem
  • Chain only: /etc/letsencrypt/live/yourdomain.com/chain.pem

Step 3: Wildcard Certificates (for *.yourdomain.com)

A wildcard certificate covers all first-level subdomains (api.yourdomain.com, app.yourdomain.com, staging.yourdomain.com) with a single certificate — no need to issue separate certificates for each subdomain.

Wildcard certificates require DNS-01 challenge validation — certbot must be able to create a TXT record in your DNS. This requires your DNS provider’s API credentials.

Cloudflare DNS (Most Common)

apt install -y python3-certbot-dns-cloudflare

# Create Cloudflare API credentials file
cat > /root/.cloudflare.ini << 'EOF'
dns_cloudflare_api_token = YOUR_CLOUDFLARE_API_TOKEN
EOF
chmod 600 /root/.cloudflare.ini

# Issue wildcard certificate
certbot certonly \
  --dns-cloudflare \
  --dns-cloudflare-credentials /root/.cloudflare.ini \
  -d yourdomain.com \
  -d "*.yourdomain.com" \
  --preferred-challenges dns-01

Manual DNS Challenge (Any DNS Provider)

# Certbot shows a TXT record to add manually
certbot certonly --manual --preferred-challenges dns \
  -d yourdomain.com -d "*.yourdomain.com"

# Follow prompts to add _acme-challenge TXT record to your DNS
# Then press Enter to verify

Step 4: Optimal Nginx TLS Configuration

cat > /etc/nginx/snippets/ssl-params.conf << 'EOF'
# TLS versions — disable old, insecure protocols
ssl_protocols TLSv1.2 TLSv1.3;

# Cipher suites — prefer forward secrecy
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;
ssl_prefer_server_ciphers off;

# Session resumption — reduces handshake overhead for repeat visitors
ssl_session_cache shared:SSL:50m;
ssl_session_timeout 1d;
ssl_session_tickets off;

# OCSP stapling — server fetches cert status, avoids client round-trip to CA
ssl_stapling on;
ssl_stapling_verify on;
resolver 1.1.1.1 8.8.8.8 valid=300s;
resolver_timeout 5s;

# HSTS — tell browsers to always use HTTPS for 1 year
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;

# Additional security headers
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
EOF

Use this snippet in all your server blocks:

server {
    listen 443 ssl http2;
    server_name yourdomain.com;

    ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;

    include /etc/nginx/snippets/ssl-params.conf;

    # ... rest of your configuration
}

Step 5: Enable HTTP/2

HTTP/2 multiplexes multiple requests over a single connection, reducing latency for resource-heavy pages. The http2 directive in the listen line enables it — your browser automatically uses HTTP/2 when available.

# HTTP/2 is enabled in the listen directive:
listen 443 ssl http2;    # ← http2 here

# Verify HTTP/2 is working
curl -I --http2 https://yourdomain.com 2>&1 | grep "HTTP/"
# Should show: HTTP/2 200

HTTP/3 / QUIC (Optional, Nginx 1.25+)

# For cutting-edge performance, enable HTTP/3 (QUIC):
listen 443 ssl http2;
listen 443 quic reuseport;  # HTTP/3 over UDP
add_header Alt-Svc 'h3=":443"; ma=86400' always;

Step 6: Automate Certificate Renewal

<code"># Certbot installs a systemd timer automatically — verify it's active
systemctl status certbot.timer

# Test renewal without actually renewing
certbot renew --dry-run

# View scheduled renewal
systemctl list-timers | grep certbot

Renewal Hook for Nginx Reload

<code">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

This hook runs after each successful renewal — Nginx reloads to pick up the new certificate without downtime.


Step 7: Test Your SSL Configuration

Online Tools

Command-Line Tests

<code"># Check certificate details
echo | openssl s_client -connect yourdomain.com:443 -servername yourdomain.com 2>/dev/null \
  | openssl x509 -noout -dates -subject -issuer

# Test TLS versions supported
nmap --script ssl-enum-ciphers -p 443 yourdomain.com

# Verify HSTS header
curl -sI https://yourdomain.com | grep -i strict

# Check certificate expiry (alert if under 30 days)
days_remaining() {
  echo $(( ($(date -d "$(echo | openssl s_client -connect $1:443 2>/dev/null \
    | openssl x509 -noout -enddate | cut -d= -f2)" +%s) - $(date +%s)) / 86400 ))
}
echo "Days until expiry: $(days_remaining yourdomain.com)"

Step 8: Self-Signed Certificates for Internal Services

For internal services (monitoring dashboards, admin panels, intranet tools) that don’t need a public CA signature:

<code"># Generate a self-signed certificate valid for 10 years
openssl req -x509 -nodes -days 3650 \
  -newkey rsa:2048 \
  -keyout /etc/ssl/private/internal.key \
  -out /etc/ssl/certs/internal.crt \
  -subj "/C=HK/ST=Hong Kong/L=Hong Kong/O=YourCompany/CN=internal.yourdomain.com" \
  -extensions v3_req \
  -addext "subjectAltName=DNS:internal.yourdomain.com,IP:10.0.0.1"

# Use in Nginx:
ssl_certificate /etc/ssl/certs/internal.crt;
ssl_certificate_key /etc/ssl/private/internal.key;

Add your self-signed certificate to your team’s trusted root store to avoid browser warnings on internal tools.


Step 9: Certificate Monitoring Alert

<code">cat > /opt/ssl-monitor.sh << 'EOF' #!/bin/bash DOMAINS=("yourdomain.com" "api.yourdomain.com" "status.yourdomain.com") ALERT_DAYS=14 for DOMAIN in "${DOMAINS[@]}"; do EXPIRY=$(echo | openssl s_client -connect ${DOMAIN}:443 -servername ${DOMAIN} 2>/dev/null \
    | openssl x509 -noout -enddate 2>/dev/null | cut -d= -f2)
  
  if [ -z "$EXPIRY" ]; then
    echo "ALERT: Cannot connect to ${DOMAIN}" | \
      mail -s "SSL Check Failed: ${DOMAIN}" admin@yourdomain.com
    continue
  fi
  
  DAYS=$(( ($(date -d "$EXPIRY" +%s) - $(date +%s)) / 86400 ))
  
  if [ $DAYS -lt $ALERT_DAYS ]; then
    echo "ALERT: ${DOMAIN} certificate expires in ${DAYS} days (${EXPIRY})" | \
      mail -s "SSL Expiry Warning: ${DOMAIN}" admin@yourdomain.com
  fi
done
EOF
chmod +x /opt/ssl-monitor.sh
crontab -l | { cat; echo "0 8 * * * /opt/ssl-monitor.sh"; } | crontab -

Conclusion

A fully configured TLS stack on your Hong Kong VPS — with Let’s Encrypt automation, wildcard certificates, HTTP/2, OCSP stapling, and HSTS — achieves SSL Labs grade A+ and eliminates certificate management toil through automated renewal hooks. The security headers configuration meets modern browser expectations and passes security audits without manual maintenance.

Secure your server: Browse Server.HK Hong Kong VPS plans — all plans support Let’s Encrypt certificates and HTTP/2 on any Nginx configuration.

Related articles

More in Website & WordPressServer setup guides