Server Administration14 min read•Updated November 2026

How to Set Up HTTPS on a VPS with Let's Encrypt and Certbot

Quick answer

To enable HTTPS on a VPS, point your domain's A record at the server's IP, open ports 80 and 443, install Certbot, and run sudo certbot --nginx -d example.com -d www.example.com (or --apache). Certbot obtains a free 90-day Let's Encrypt certificate, configures your web server and installs a timer that renews it automatically. Confirm renewal works with sudo certbot renew --dry-run.

HTTPS is no longer optional. Browsers label plain-HTTP pages as "Not secure", login forms and payment flows require encryption, and HTTP/2 is only used by browsers over TLS. On a VPS you control the web server yourself, so you are responsible for getting and renewing certificates. The good news is that Let's Encrypt issues trusted certificates for free, and Certbot automates almost the entire process.

This guide walks through the complete setup on Ubuntu or Debian with Nginx or Apache, explains what Certbot changes on your server, and covers renewal, wildcard certificates, Cloudflare and the errors people hit most often.

How Let's Encrypt and Certbot Work

Let's Encrypt is a free, automated certificate authority. Before it issues a certificate it must confirm that you control the domain. This is done with an ACME challenge. Certbot is the most widely used ACME client: it requests the certificate, completes the challenge, saves the files and (optionally) edits your web server configuration.

There are two challenge types you will use on a VPS:

  • HTTP-01: Let's Encrypt fetches a token from http://your-domain/.well-known/acme-challenge/ on port 80. This is the default and works for normal (non-wildcard) certificates. Port 80 must be reachable from the internet.
  • DNS-01: you prove control by creating a TXT record under _acme-challenge.your-domain. This is the only way to get a wildcard certificate (*.example.com) and it works even when port 80 is closed.

Certificates are currently valid for 90 days. Certbot renews them automatically when they are within 30 days of expiry, so once renewal is configured you rarely need to touch it. Let's Encrypt has announced plans to shorten certificate lifetimes further over time, which makes automatic renewal even more important than manual processes.

Prerequisites

  • A Linux VPS with a public IPv4 address (Ubuntu 22.04/24.04 or Debian 12 are used in the examples) and a user with sudo.
  • A registered domain name and access to its DNS settings.
  • Nginx or Apache installed and serving your site over HTTP.
  • Ports 80 and 443 open in any firewall in front of the server.

Step 1: Point Your Domain at the VPS

Create an A record for the root domain and, if you use it, the www host, both pointing to your VPS IPv4 address. If your server also has IPv6, add matching AAAA records; otherwise do not create AAAA records at all, because Let's Encrypt prefers IPv6 and validation fails if an AAAA record points somewhere that does not answer.

example.com.      A     203.0.113.10
www.example.com.  A     203.0.113.10

Wait for the record to propagate, then confirm it from your own computer:

dig +short example.com A
dig +short www.example.com A

Both commands should return your VPS IP. You can also check propagation with our DNS lookup tool.

Step 2: Open Ports 80 and 443

If you use UFW, allow both web ports. Nginx and Apache install application profiles that make this one line:

# Nginx
sudo ufw allow 'Nginx Full'
# Apache
sudo ufw allow 'Apache Full'
sudo ufw status

Keep port 80 open even after HTTPS works. HTTP-01 renewals need it, and visitors who type the bare domain still arrive on port 80 before being redirected. If you are new to UFW, follow our UFW firewall guide first so you do not lock yourself out of SSH.

Step 3: Install Certbot

The Certbot project recommends installing it as a snap, which always gives you a current version and sets up automatic renewal:

sudo apt update
sudo apt install -y snapd
sudo snap install core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

If you prefer distribution packages, Ubuntu and Debian ship Certbot and its web server plugins in their repositories:

# Nginx
sudo apt install -y certbot python3-certbot-nginx
# Apache
sudo apt install -y certbot python3-certbot-apache

Use one method, not both. Two installs create two renewal timers and confusing paths.

Step 4: Issue the Certificate (Nginx)

Certbot's Nginx plugin finds the server block whose server_name matches your domain, so make sure that directive is set correctly first:

server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/example.com;
    index index.html index.php;
}
sudo nginx -t && sudo systemctl reload nginx
sudo certbot --nginx -d example.com -d www.example.com

On the first run Certbot asks for an email address (used for important account notices) and for acceptance of the subscriber agreement. It then:

  1. Completes the HTTP-01 challenge through Nginx.
  2. Saves the certificate in /etc/letsencrypt/live/example.com/.
  3. Adds listen 443 ssl, ssl_certificate and ssl_certificate_key lines to your server block.
  4. Adds a permanent redirect from HTTP to HTTPS (current Certbot versions do this by default).
  5. Reloads Nginx.

The files you will see referenced are:

FilePurpose
fullchain.pemYour certificate plus the intermediate chain. Use this as the server certificate.
privkey.pemThe private key. Never share it or commit it to Git.
cert.pem / chain.pemThe certificate and chain separately, for software that needs them split.

The files in live/ are symlinks that Certbot updates on every renewal, so always reference these paths rather than copying the files elsewhere.

Step 4 (Alternative): Issue the Certificate (Apache)

The process is the same with the Apache plugin. Confirm that your virtual host has the correct ServerName and ServerAlias, then run:

sudo apachectl configtest
sudo certbot --apache -d example.com -d www.example.com

Certbot creates an SSL virtual host (usually example.com-le-ssl.conf), enables mod_ssl if needed and adds the redirect.

Step 5: Verify the Certificate

curl -I https://example.com
curl -I http://example.com        # should return 301 to https://
sudo certbot certificates          # lists domains and expiry dates
echo | openssl s_client -connect example.com:443 -servername example.com 2>/dev/null | openssl x509 -noout -dates -issuer

The last command shows the validity dates and confirms the issuer is Let's Encrypt. Open the site in a browser and check that the padlock shows no mixed-content warnings. If the browser still warns, the page is loading images or scripts over http://; change those URLs to https:// or to relative paths.

Step 6: Confirm Automatic Renewal

Both installation methods create a systemd timer that runs certbot renew twice a day. Check that it exists and test renewal without touching your real certificate:

# snap install
systemctl list-timers | grep -i certbot
# apt install
systemctl status certbot.timer

sudo certbot renew --dry-run

A successful dry run means renewal will work. With the Nginx and Apache plugins, Certbot reloads the web server after renewing. If you used --standalone or --webroot, or another service (a mail server, a Node.js app terminating TLS itself) reads the certificate, add a deploy hook so it picks up the new files:

sudo certbot renew --deploy-hook "systemctl reload nginx"

Certbot stores the hook in the domain's renewal file under /etc/letsencrypt/renewal/, so future automatic renewals use it too.

Wildcard Certificates with DNS-01

Use a wildcard certificate when you serve many subdomains, for example per-customer subdomains in a SaaS app. Wildcards require the DNS-01 challenge:

sudo certbot certonly --manual --preferred-challenges dns \
  -d example.com -d '*.example.com'

Certbot shows a TXT value to add at _acme-challenge.example.com. Manual mode cannot renew automatically, because you must create the record by hand each time. For unattended renewal, install the DNS plugin for your provider (for example certbot-dns-cloudflare) and give it an API token restricted to editing DNS for that zone. Store the credentials file with chmod 600.

Using Let's Encrypt Behind Cloudflare

If your domain is proxied through Cloudflare (orange cloud), visitors see Cloudflare's certificate, but you should still encrypt the connection between Cloudflare and your VPS. Install a Let's Encrypt certificate on the origin as above and set Cloudflare's SSL/TLS mode to Full (strict). Avoid "Flexible" mode: it sends traffic to your server unencrypted and, combined with an HTTP-to-HTTPS redirect on the origin, causes an endless redirect loop.

Optional Hardening: HSTS and Modern TLS

Certbot's default configuration (/etc/letsencrypt/options-ssl-nginx.conf) already disables obsolete protocols. Once you are sure every subdomain works over HTTPS, you can add an HSTS header so browsers never try plain HTTP again:

add_header Strict-Transport-Security "max-age=31536000" always;

Start without includeSubDomains and preload. HSTS is cached by browsers for the whole max-age, so a mistake cannot be undone quickly.

SkyRainCloud Plans for This Workload

TLS adds very little CPU load on modern processors, so HTTPS does not change which plan you need. Size the server for your application; the entry 2 vCore / 8 GB plans comfortably serve HTTPS for business websites and APIs.

Intel Xeon Platinum 8269CY VPS

KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — Intel28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthBusiness websites, small apps, scheduled jobs and botsOrder
VPS 2 — Intel416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,169/monthBusiness software, mid-size databases, several sites on one serverCheck stock
VPS 3 — Intel832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,249/monthERP/CRM stacks, heavier databases, multiple production appsCheck stock
VPS 4 — Intel1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,299/monthHigh-memory workloads and consolidated production serversCheck stock

AMD EPYC 7C13 VPS

Dedicated KVM vCores on AMD EPYC 7C13 (up to 3.70 GHz) with DDR4 ECC memory, NVMe SSD and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — AMD28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthWebsites, small APIs, bots, staging and VPN serversOrder
VPS 2 — AMD416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,299/monthWooCommerce, Node.js/Python backends, Docker Compose stacks, CI runnersOrder
VPS 3 — AMD832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,499/monthProduction databases, high-traffic sites, multi-container appsOrder
VPS 4 — AMD1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,899/monthLarge production workloads, SaaS platforms, analytics, in-memory cachesOrder

Prices are monthly in INR as listed on the SkyRainCloud store (verified 2026-11-14). Stock and final pricing are shown on the product page at checkout.

Common Errors and How to Fix Them

ErrorLikely causeFix
Timeout during connect / connection refusedPort 80 blocked by UFW, a cloud firewall or nothing listeningOpen port 80, make sure Nginx/Apache is running, test with curl -I http://example.com from outside
NXDOMAIN or "DNS problem"A record missing or not yet propagatedCheck with dig; wait for propagation
Invalid response from IPv6 addressAn AAAA record points to a host that does not serve the siteRemove the AAAA record or configure IPv6 on the VPS
Could not automatically find a matching server blockserver_name does not list the domainFix server_name, reload Nginx, run Certbot again
too many certificates already issuedHit a Let's Encrypt rate limit after repeated attemptsUse --dry-run or --staging while testing; wait for the limit window to reset
ERR_TOO_MANY_REDIRECTSCloudflare "Flexible" SSL plus origin redirectSwitch Cloudflare to Full (strict)

When experimenting, add --staging (or --test-cert) to issue certificates from Let's Encrypt's staging environment, which has much higher limits. Staging certificates are not trusted by browsers, so re-run without the flag once everything works.

Quick Checklist

  1. A (and only valid AAAA) records point to the VPS.
  2. Ports 80 and 443 are open.
  3. Certbot installed by one method only.
  4. certbot --nginx or --apache completed and HTTP redirects to HTTPS.
  5. certbot renew --dry-run succeeds.
  6. No mixed-content warnings in the browser.

Frequently Asked Questions

Is a Let's Encrypt certificate as secure as a paid SSL certificate?
The encryption is the same. Let's Encrypt issues Domain Validated (DV) certificates trusted by all major browsers. Paid certificates are mainly useful when you need Organization or Extended Validation, a warranty, or a support contract.
How long does a Let's Encrypt certificate last?
Currently 90 days. Certbot renews automatically when a certificate is within 30 days of expiry, so with a working renewal timer you never need to renew by hand. Let's Encrypt has announced it will shorten lifetimes further, so rely on automation rather than calendar reminders.
Do I need to keep port 80 open after enabling HTTPS?
Yes, if you use the HTTP-01 challenge. Renewals validate over port 80, and visitors who type the domain without https still arrive there before being redirected. Only the DNS-01 challenge works with port 80 closed.
Can I get one certificate for several domains?
Yes. Pass multiple -d flags, for example -d example.com -d www.example.com -d shop.example.com. Each name must point to the server. A wildcard certificate (*.example.com) needs the DNS-01 challenge.
How do I renew a Let's Encrypt certificate manually?
Run sudo certbot renew. It only renews certificates close to expiry; add --force-renewal to renew immediately, but use that sparingly because of rate limits.
Will HTTPS slow down my VPS?
Not noticeably. Modern CPUs accelerate the cryptography in hardware, and HTTPS enables HTTP/2 in browsers, which often makes sites faster. Size your VPS for the application, not for TLS.
Does Certbot work with Node.js, Python or Docker apps?
Yes. The common pattern is to keep the app on a local port and let Nginx terminate HTTPS as a reverse proxy, then run certbot --nginx. If the app terminates TLS itself, use certbot certonly and point the app at fullchain.pem and privkey.pem with a deploy hook to restart it.
How do I use Let's Encrypt with Cloudflare?
Install the certificate on your VPS as normal and set Cloudflare SSL/TLS mode to Full (strict). Do not use Flexible mode, which leaves the Cloudflare-to-server connection unencrypted and causes redirect loops.
What happens if renewal fails?
The current certificate keeps working until it expires, and Certbot retries twice a day. Run sudo certbot renew --dry-run to see the error; the usual causes are a closed port 80, changed DNS or a modified server block.
Which SkyRainCloud VPS plan should I use for an HTTPS website?
Choose based on the application, not on HTTPS. A business website or small API runs well on the entry 2 vCore / 8 GB plan; move up to 4 vCores / 16 GB for WooCommerce or several sites. Every plan includes full root access, so you can install Certbot and edit the web server configuration yourself.
Instant UPI • ₹649/mo
Fast KVM Cloud Provisioning