Securing your website is essential in today's digital world. Using free SSL/TLS certificates from Let's Encrypt is a popular way to enable HTTPS on your site. This guide explains how to set up Let's Encrypt with the Lighttpd web server to ensure your website is secure and trustworthy.

Prerequisites

  • A server running Lighttpd installed and configured.
  • Root or sudo access to your server.
  • Domain name pointing to your server's IP address.
  • Basic knowledge of command-line operations.

Installing Certbot

Certbot is a popular tool for obtaining and renewing Let's Encrypt certificates. To install Certbot on a Debian or Ubuntu server, run:

sudo apt update

sudo apt install certbot

For other distributions, follow the instructions on the Certbot website.

Obtaining an SSL Certificate

Stop Lighttpd temporarily to free port 80:

sudo systemctl stop lighttpd

Run Certbot with the webroot plugin, replacing yourdomain.com with your actual domain:

sudo certbot certonly --webroot -w /var/www/html -d yourdomain.com

After successful validation, your certificate files will be stored in /etc/letsencrypt/live/yourdomain.com/.

Configuring Lighttpd to Use SSL

Create or edit your Lighttpd configuration file, typically located at /etc/lighttpd/lighttpd.conf. Add or modify the following lines:

\$SERVER["socket"] == ":80" {

server.redirect = ("" => "https://yourdomain.com/")

}

And for SSL:

\$SERVER["socket"] == ":443" {

ssl.engine = "enable"

ssl.pemfile = "/etc/letsencrypt/live/yourdomain.com/fullchain.pem"

ssl.privkey = "/etc/letsencrypt/live/yourdomain.com/privkey.pem"

}

Restarting Lighttpd

Apply the changes by restarting Lighttpd:

sudo systemctl start lighttpd

Automating Certificate Renewal

Certbot automatically renews certificates, but you should set up a cron job to handle this. To test renewal, run:

sudo certbot renew --dry-run

If successful, add a cron job to renew certificates periodically:

sudo crontab -e

And add the line:

0 3 * * * /usr/bin/certbot renew --quiet && systemctl reload lighttpd

Conclusion

Using Let's Encrypt with Lighttpd is a straightforward way to secure your website with HTTPS. Remember to keep your certificates renewed and your server configuration updated for maximum security and performance.