Linux
Web-Server
Webserver Ssl

SSL Configuration with Certbot

NGINX SSL Configuration

Install Certbot

  1. Install Core Snap and Certbot

    Install Core Snap and Certbot:

    sudo snap install core; sudo snap refresh core
    sudo apt remove certbot
    sudo snap install --classic certbot
    sudo apt install certbot python3-certbot-nginx
    sudo ln -s /snap/bin/certbot /usr/bin/certbot

Configure NGINX for SSL

  1. Edit NGINX Configuration

    Open your NGINX site configuration file:

    sudo nano /etc/nginx/sites-available/example-conf

    Ensure it includes SSL settings. For example:

    server {
        listen 80;
        server_name <domain_name>;
        return 301 https://$host$request_uri;
    }
     
    server {
        listen 443 ssl;
        server_name <domain_name>;
     
        ssl_certificate /etc/letsencrypt/live/<domain_name>/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/<domain_name>/privkey.pem;
     
        # Other SSL settings
        ...
    }
  2. Test NGINX Configuration

    Test the NGINX configuration for errors:

    sudo nginx -t
  3. Reload NGINX

    Apply the changes:

    sudo systemctl reload nginx

Obtain an SSL Certificate

  1. Run Certbot for NGINX

    Obtain and install the SSL certificate:

    sudo certbot --nginx -d <domain_name>

Verify Auto-Renewal

  1. Check Certbot Renewal Status

    Verify the status of the renewal service:

    sudo systemctl status snap.certbot.renew.service
  2. Dry-Run Renewal

    Simulate a renewal to ensure it works:

    sudo certbot renew --dry-run

Apache SSL Configuration

Install Certbot

  1. Install Certbot for Apache

    Install Certbot and Apache plugin:

    sudo apt update
    sudo apt install certbot python3-certbot-apache

Configure Apache for SSL

  1. Edit Apache Configuration

    Open your Apache site configuration file:

    sudo nano /etc/apache2/sites-available/your_domain.conf

    Ensure it includes SSL settings. For example:

    <VirtualHost *:80>
        ServerName <domain_name>
        Redirect permanent / https://<domain_name>/
    </VirtualHost>
     
    <VirtualHost *:443>
        ServerName <domain_name>
     
        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/<domain_name>/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/<domain_name>/privkey.pem
     
        # Other SSL settings
        ...
    </VirtualHost>
  2. Test Apache Configuration

    Test the Apache configuration for errors:

    sudo apache2ctl configtest
  3. Reload Apache

    Apply the changes:

    sudo systemctl reload apache2

Obtain an SSL Certificate

  1. Run Certbot for Apache

    Obtain and install the SSL certificate:

    sudo certbot --apache

Verify Auto-Renewal

  1. Check Certbot Timer Status

    Verify the status of the renewal timer:

    sudo systemctl status certbot.timer
  2. Dry-Run Renewal

    Simulate a renewal to ensure it works:

    sudo certbot renew --dry-run

Summary

  • NGINX: Install Certbot, configure SSL settings, obtain certificates, and verify auto-renewal.
  • Apache: Install Certbot, configure SSL settings, obtain certificates, and verify auto-renewal.

Make sure to replace <domain_name> with your actual domain and adjust file paths according to your setup.


🧙 AI Wizard - Instant Page Insights

Click the button below to analyze this page.
Get an AI-generated summary and key insights in seconds.
Powered by Perplexity AI!