VPS guide
How to Install Nginx and a Free Let's Encrypt Certificate on Ubuntu
Short answer
Point your domain's A records at the VPS, install Nginx, create a server block for the domain, then run sudo certbot --nginx -d example.co.uk -d www.example.co.uk. Certbot gets the certificate, switches the site to HTTPS and sets up automatic renewal.
This guide uses Ubuntu 24.04; the steps are the same on Debian 12. Replace example.co.uk with your own domain throughout. You'll need a firewall that allows ports 80 and 443, and the domain's DNS pointing at the server before you request the certificate.
Point the domain at the server
At your DNS provider, create A records for example.co.uk and www pointing at your VPS's IP address. From your own computer, check they've updated:
nslookup example.co.uk
nslookup www.example.co.ukBoth should return your server's IP address. Let's Encrypt checks the domain over the internet, so the certificate request fails until DNS is right.
Install Nginx
sudo apt update
sudo apt install nginx
sudo ufw allow 'Nginx Full'Visit http://your-vps-ip and you should see the Welcome to nginx page.
Create the site folder
sudo mkdir -p /var/www/example.co.uk/html
sudo chown -R $USER:$USER /var/www/example.co.uk/html
echo "<h1>It works</h1>" > /var/www/example.co.uk/html/index.htmlAdd a server block
sudo nano /etc/nginx/sites-available/example.co.ukserver {
listen 80;
listen [::]:80;
server_name example.co.uk www.example.co.uk;
root /var/www/example.co.uk/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}Turn the site on, test the configuration and reload Nginx:
sudo ln -s /etc/nginx/sites-available/example.co.uk /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginxnginx -t names the file and line of any mistake. Reload only after it reports that the test is successful. Visit http://example.co.uk and you should see "It works".
Get the certificate
Install Certbot with its Nginx plugin, then request one certificate covering both names:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d example.co.uk -d www.example.co.ukCertbot asks for an email address and for you to accept the terms. It then proves you control the domain, saves the certificate under /etc/letsencrypt/live/example.co.uk/, and adds the HTTPS settings to your server block, including a redirect from HTTP. If it asks whether to redirect, choose redirect. Certbot's own instructions install it with snap; the Ubuntu package above does the same job.
Check renewal
Let's Encrypt certificates currently last 90 days. The Certbot package adds a timer that renews them before they expire. Check the timer and run a test renewal:
systemctl list-timers | grep certbot
sudo certbot renew --dry-runRunning an app behind Nginx
For a Node.js, Python or Docker app listening on a local port, replace the location / block with a proxy, then test and reload Nginx as before:
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}Keep the app itself listening on 127.0.0.1 so the only way in is through Nginx and HTTPS.
UK VPS hosting with full root access
Guaranteed AMD EPYC cores, SSD RAID storage and DDoS protection on every plan, from £5.99 a month with no VAT to add. Need faster cores? Upgrade to Ryzen.
See VPS plansQuestions
Why does Certbot fail with a timeout or unauthorized error?
Usually DNS doesn't point at this server yet, or port 80 is blocked. Let's Encrypt connects on port 80 to check the domain, so keep it open even after the site redirects to HTTPS.
Is a Let's Encrypt certificate as good as a paid one?
It gives the same encryption and the same padlock in the browser. Paid certificates add organisation validation or warranties, which most sites don't need.
Can I get a wildcard certificate?
Yes, but only with a DNS challenge. Certbot has to create a TXT record, which needs a DNS plugin for your provider or a manual step at every renewal.
Do I need to renew the certificate myself?
No. Certbot's timer renews certificates before they expire and reloads Nginx. Run sudo certbot renew --dry-run once to check it works.
Related guides
Sources
Commands are for Ubuntu 24.04, Debian 12 and AlmaLinux 9, as of 16 October 2026. If something here no longer matches what you see, tell us and we'll update it.