Fixing a Broken HTTPS on a 1‑GB VPS: Certbot, Nginx, and File Permissions

A 1‑GB VPS is a common starting point for small sites, but a mis‑configured certificate or wrong file ownership can bring HTTPS down instantly. The following steps show how to get a fresh, secure cert with Certbot, tighten Nginx’s file permissions, and verify the result—all in under 30 minutes.

1. Verify the Current State

sudo systemctl status nginx
sudo certbot certificates

If nginx is active but the browser shows “connection not private”, the cert file is missing or unreadable. Check the cert directory:

sudo ls -l /etc/letsencrypt/live/example.com/

Typical output:

total 0
lrwxrwxrwx 1 root root  30 Dec  2 12:00 cert.pem -> ../../archive/example.com/cert1.pem
lrwxrwxrwx 1 root root  30 Dec  2 12:00 chain.pem -> ../../archive/example.com/chain1.pem
lrwxrwxrwx 1 root root  30 Dec  2 12:00 fullchain.pem -> ../../archive/example.com/fullchain1.pem
lrwxrwxrwx 1 root root  30 Dec  2 12:00 privkey.pem -> ../../archive/example.com/privkey1.pem

If any of these symlinks are broken, or the archive folder is empty, the cert is corrupted.

2. Re‑issue the Certificate

On a fresh VPS, the simplest fix is to re‑issue the cert:

sudo certbot --nginx -d example.com -d www.example.com

Certbot will:

  1. Stop Nginx temporarily.
  2. Obtain a new cert via the HTTP‑01 challenge.
  3. Restart Nginx with the new cert.

If you prefer the standalone mode (e.g., Nginx is already mis‑configured), use:

sudo certbot certonly --standalone -d example.com

Then manually point Nginx to the new cert files:

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

3. Harden File Permissions

Let’s ensure that only the root user can read the private key, and that Nginx can still serve the cert.

sudo chown root:root /etc/letsencrypt/live/example.com/privkey.pem
sudo chmod 400 /etc/letsencrypt/live/example.com/privkey.pem

The live directory itself should be owned by root and readable by root and the www-data group (the default Nginx user on Debian/Ubuntu). The archive directory is a symlink target; its permissions are less critical because the live symlinks are the only ones Nginx follows.

If you’re running Nginx as a non‑default user (e.g., nginx), adjust the group accordingly:

sudo chgrp nginx /etc/letsencrypt/live/example.com
sudo chmod 750 /etc/letsencrypt/live/example.com

4. Verify the HTTPS Stack

curl -I https://example.com

You should see HTTP/2 200 and a Strict-Transport-Security header. If the header is missing, add it to your Nginx config:

add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;

5. Automate Renewal and Permission Checks

Certbot’s renewal hook can re‑apply permissions after each renewal:

sudo tee /etc/letsencrypt/renewal-hooks/post/perm.sh <<'EOF'
#!/bin/sh
chown root:root /etc/letsencrypt/live/example.com/privkey.pem
chmod 400 /etc/letsencrypt/live/example.com/privkey.pem
EOF
sudo chmod +x /etc/letsencrypt/renewal-hooks/post/perm.sh

Now, certbot renew will run this script automatically.

6. Common Pitfalls

SymptomLikely CauseFix
SSL_ERROR_NO_CYPHER_OVERLAPOld OpenSSL on the client, or Nginx using weak ciphersUpdate OpenSSL; configure ssl_ciphers to a modern list
403 Forbidden on /etc/letsencrypt/live/Permissions too restrictiveEnsure Nginx user can read the live symlinks
“Connection timed out” during renewalPort 80 blockedOpen port 80 in the VPS firewall (ufw allow 80/tcp)

7. Quick Reference

# Re‑issue cert
sudo certbot --nginx -d example.com -d www.example.com

# Harden key
sudo chown root:root /etc/letsencrypt/live/example.com/privkey.pem
sudo chmod 400 /etc/letsencrypt/live/example.com/privkey.pem

# Verify
curl -I https://example.com

8. Resources

See also