siemer-solutions.de

Clean and simple it-solutions in Eberswalde and Berlin/Brandenburg




Securing Your Website with Let's Encrypt and Certbot

In today's digital landscape, HTTPS (Hypertext Transfer Protocol Secure) is no longer a luxury but a necessity. It encrypts communication between your website and your users, protecting sensitive data, improving SEO rankings, and building trust. However, acquiring and managing SSL/TLS certificates can sometimes be complex and costly.

Enter Let's Encrypt and Certbot – a powerful, free, and automated solution for obtaining and renewing SSL certificates. At Siemer Solutions, we advocate for secure web practices, and implementing HTTPS with these tools is a fundamental step in that direction. This article will guide you through the process, demonstrating how easy it is to secure your domain.


Why HTTPS?

Before diving into the "how," let's quickly reiterate the "why":


What is Let's Encrypt?

Let's Encrypt is a free, automated, and open Certificate Authority (CA) provided by the Internet Security Research Group (ISRG). It issues SSL/TLS certificates that are trusted by virtually all browsers, without any cost. Its mission is to make HTTPS encryption accessible to everyone.

What is Certbot?

Certbot is a free, open-source software tool from the Electronic Frontier Foundation (EFF) that automates the process of obtaining and renewing Let's Encrypt certificates. It simplifies the setup of HTTPS on your server, handling certificate issuance, installation, and automatic renewals. Certbot supports a wide range of web servers, including Nginx and Apache.


Step-by-Step Guide: Securing Your Domain

This guide assumes you have a server running a web server (Nginx or Apache) and a domain name pointing to your server's IP address. For this tutorial, we'll focus on Nginx, a common choice for its performance and flexibility.

Need assistance with server setup, domain configuration, or ongoing maintenance? Siemer Solutions offers expert services to handle all aspects of your web infrastructure, ensuring your site is always secure and performing optimally.

Step 1: SSH into Your Server

First, connect to your server via SSH:

ssh your_user@your_domain.com

Replace your_user with your actual username and your_domain.com with your domain.

Step 2: Update Your System and Install Certbot

It's always a good idea to update your package lists and upgrade existing packages before installing new software.

sudo apt update sudo apt upgrade -y

Next, install Certbot. The installation method depends on your operating system and web server. For Ubuntu and Nginx:

sudo apt install certbot python3-certbot-nginx

Step 3: Configure Your Nginx Server Block

Before running Certbot, ensure your Nginx server block (configuration file for your domain, typically in /etc/nginx/sites-available/) is correctly set up for your domain. It should include a server_name directive that matches your domain(s).

Here's a minimal example for your_domain.com and www.your_domain.com:

# /etc/nginx/sites-available/your_domain.com

server {
    listen 80;
    listen [::]:80;
    server_name your_domain.com www.your_domain.com;

    # Optional: Set root if you have static content here
    # root /var/www/your_domain.com;
    # index index.html index.htm;

    # No 'ssl' directives yet. Certbot will add them.
    # No 'proxy_pass' if you're serving static content directly,
    # otherwise, ensure your application is running and accessible.

    # If you have a Quart/Python app, your location block might look like this:
    # location / {
    #     proxy_pass http://unix:/path/to/your/app.sock;
    #     proxy_set_header Host $host;
    #     proxy_set_header X-Real-IP $remote_addr;
    #     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    #     proxy_set_header X-Forwarded-Proto $scheme;
    #     proxy_redirect off;
    # }
}

Important: * Replace your_domain.com with your actual domain. * Activate your server block: Create a symbolic link from sites-available to sites-enabled:

sudo ln -s /etc/nginx/sites-available/your_domain.com /etc/nginx/sites-enabled/ * Test Nginx configuration: sudo nginx -t You should see syntax is ok and test is successful.

Step 4: Run Certbot to Obtain and Install Certificates

Now, execute Certbot. The nginx plugin will automatically configure Nginx for you.

sudo certbot --nginx -d your_domain.com -d www.your_domain.com * Replace your_domain.com and www.your_domain.com with your actual domain names. * Certbot will guide you through a few prompts: Enter an email address for urgent renewal notices. Agree to the Let's Encrypt Terms of Service. Choose whether to redirect HTTP traffic to HTTPS (recommended: 2: Redirect).

If successful, Certbot will congratulate you and show you the paths to your certificates.

Step 5: Verify Your Certificate Installation

Open your web browser and navigate to your domain using https://your_domain.com. You should see a padlock icon in the address bar, indicating a secure connection. Clicking on the padlock will provide details about your certificate. Step 6: Test Automatic Renewal

Let's Encrypt certificates are valid for 90 days. Certbot automates the renewal process. A cron job or systemd timer is usually set up automatically during installation to run certbot renew twice a day.

You can test the renewal process manually (it won't actually renew if the certificate is not near expiry):