If you’re running a website on a LEMP stack, securing it with HTTPS is an essential part of maintaining a safe and reliable web server. HTTPS encrypts traffic between your visitors and your website, protects information in transit, and helps prevent browsers from displaying warnings about insecure connections.
The good news is that you don’t need to purchase an SSL certificate. Let’s Encrypt provides free SSL/TLS certificates, and Certbot makes it possible to obtain, install, and renew them automatically.
In this guide, we’ll walk through installing Let’s Encrypt on a Linux server running Nginx, configuring HTTPS, redirecting HTTP traffic, and testing automatic certificate renewal.
What You’ll Need
Before you begin, make sure you have:
- A Linux server running Ubuntu or Debian.
- Nginx installed and serving your website.
- A registered domain name pointing to your server’s public IP address.
- SSH access and a user account with
sudoprivileges. - Ports 80 (HTTP) and 443 (HTTPS) accessible through your firewall and any cloud firewall or router in front of the server.
Your website should already be accessible through its domain name. In the examples below, we’ll use example.com and www.example.com. Replace these with your actual domain names.
Step 1: Update Your Server
Connect to your server over SSH and update the package lists and installed packages.
sudo apt update
sudo apt upgrade -y
Keeping your system updated helps reduce security risks and ensures your server has current packages before you configure HTTPS.
Step 2: Install Snapd and Certbot
We’ll use Certbot to request a certificate from Let’s Encrypt and configure Nginx to use it.
First, install Snap if it isn’t already available:
sudo apt install snapd -y
On Debian, additional Snap setup may be necessary. Follow your distribution’s instructions if the Snap service isn’t ready.
Install Certbot using its official Snap package:
sudo snap install certbot --classic
Make the Certbot command available in your usual command path:
sudo ln -s /snap/bin/certbot /usr/local/bin/certbot
If that path already exists, inspect the existing installation before changing anything.
Verify that Certbot is installed:
certbot --version
You should see the installed version number.
Step 3: Verify Your Nginx Configuration
Before requesting a certificate, confirm that Nginx is running and your website’s server block is configured correctly.
Check the service:
sudo systemctl status nginx
If necessary, start Nginx and enable it at boot:
sudo systemctl enable --now nginx
Test the Nginx configuration:
sudo nginx -t
A successful test should report that the configuration syntax is OK and the configuration test is successful.
On Ubuntu and Debian, Nginx site configurations are commonly stored in:
/etc/nginx/sites-available/
/etc/nginx/sites-enabled/
For example, your HTTP server block might look like this:
server {
listen 80;
listen [::]:80;
server_name example.com www.example.com;
root /var/www/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
}
This is a basic example. If your website uses PHP, WordPress, a reverse proxy, or custom routing, retain the appropriate existing configuration rather than replacing it with this example.
If you’re using a separate site configuration file, enable it if necessary:
sudo ln -s /etc/nginx/sites-available/example \
/etc/nginx/sites-enabled/example
Only run this command if the link does not already exist.
Test the configuration and reload Nginx:
sudo nginx -t
sudo systemctl reload nginx
Step 4: Configure Your Firewall
Let’s Encrypt must be able to reach your server to validate your domain. For the standard HTTP validation method, port 80 must be accessible. Port 443 must also be available for secure HTTPS traffic.
If you’re using UFW, check its status:
sudo ufw status
If the firewall is enabled and these ports aren’t already allowed, run:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
If your server is hosted by a cloud provider, check its security group or network firewall as well. If you’re running the server behind a router, confirm that the required ports are forwarded correctly.
Be careful when changing firewall rules remotely. Make sure SSH access remains permitted.
Step 5: Request and Install Your Let’s Encrypt Certificate
With Nginx configured and your domain reachable, you’re ready to request a certificate.
Run:
sudo certbot --nginx -d example.com -d www.example.com
Replace the example domains with your own.
Certbot will contact Let’s Encrypt, validate your domain, obtain the certificate, and configure Nginx to use HTTPS. You may be asked to provide an email address, agree to the terms of service, and choose whether HTTP requests should redirect to HTTPS.
If you don’t use the www version of your domain, leave it out of the command.
When the process finishes successfully, open your website at:
Certbot normally updates the relevant Nginx server block to use the certificate and private key stored under /etc/letsencrypt/.
Important: Back up your Nginx configuration before making significant manual changes. Certbot modifies server configuration files, so review those changes if you have a complex setup.
Step 6: Verify HTTPS Is Working
Open your website in a browser and confirm that the connection is secure.
You can also check the response from the command line:
curl -I https://example.com
A successful response will generally include an HTTP status such as 200 OK or a redirect status, depending on how your site is configured.
To inspect the certificates managed by Certbot, run:
sudo certbot certificates
Check that the correct domains appear and that the certificate has a valid expiration date.
You should also verify that your HTTP-to-HTTPS redirect works if you enabled it. Run:
curl -I http://example.com
If redirection is configured, the response should normally contain a 301 or 308 status and a Location header pointing to the HTTPS address.
Step 7: Test Automatic Certificate Renewal
Let’s Encrypt certificates have limited lifetimes, so automatic renewal is important.
Certbot’s Snap installation includes renewal scheduling. You should still test the renewal process to confirm that it works with your server configuration.
Run:
sudo certbot renew --dry-run
This simulates renewal without replacing your live certificate.
If the test succeeds, Certbot can complete the renewal process using your current setup.
To inspect scheduled systemd tasks, run:
systemctl list-timers --all
The exact scheduling mechanism depends on your Certbot installation. Avoid creating duplicate cron jobs or systemd timers unless you’ve verified that automatic renewal is not already configured.
Step 8: Troubleshoot Common Nginx SSL Problems
Certbot cannot validate the domain
Check that your domain’s DNS records point to the correct public IP address. If you’re requesting a certificate for both the root domain and www, verify both records.
Make sure port 80 is reachable from the internet and that Nginx is listening on the expected address.
Nginx fails after the certificate is installed
Run:
sudo nginx -t
If the test reports a configuration error, correct it before reloading Nginx.
If necessary, inspect the active server configuration:
sudo nginx -T
This displays the effective Nginx configuration, including included files. Review the output carefully before sharing it, because custom configurations can contain sensitive information.
HTTPS works, but the browser still shows warnings
If the certificate is valid but the browser reports mixed content, your website may still be loading resources such as images, scripts, or stylesheets over HTTP.
Update those resource URLs to HTTPS. If you’re running WordPress, check the configured site URLs and any hard-coded links in your theme or plugins.
Automatic renewal fails
Run the renewal simulation again:
sudo certbot renew --dry-run
Review the error message and check DNS, firewall access, Nginx configuration, and any recent changes to your domain or server.
If you use custom certificate paths or manually manage your Nginx TLS configuration, make sure your renewal and reload process is appropriate for that setup.
Final Thoughts
Installing Let’s Encrypt on a LEMP server is a practical way to secure your website without paying for a commercial SSL certificate. Certbot simplifies the process by handling domain validation, certificate installation, and renewal scheduling.
Once your website is working over HTTPS, consider reviewing your security headers, keeping Nginx and PHP updated, configuring secure cookies, and checking that your application consistently uses HTTPS.
For the latest installation instructions, consult the official Certbot instructions and Ubuntu Server TLS certificate documentation.
Remember: HTTPS is an important layer of security, but it doesn’t replace regular server updates, secure application configuration, strong authentication, or reliable backups.







