GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Come proteggere Nginx con Let's Encrypt su Ubuntu 20.04

In questo articolo, avremo spiegato i passaggi necessari per proteggere Nginx con Let's encrypt su Ubuntu 20.04 LTS. Prima di continuare con questo tutorial, assicurati di aver effettuato l'accesso come utente con sudo privilegi. Tutti i comandi in questo tutorial devono essere eseguiti come utente non root.

Let's Encrypt è un'autorità di certificazione gratuita, automatizzata e aperta sviluppata dall'Internet Security Research Group (ISRG) che fornisce certificati SSL gratuiti. Let's Encrypt utilizza un software client (certbot) che automatizza il processo di creazione, convalida, firma, implementazione e rinnovo dei certificati.

Prerequisito:

  • Sistema operativo con Ubuntu 20.04
  • Indirizzo IPv4 del server con privilegi di superutente (accesso root)
  • Terminale Gnome per desktop Linux
  • Client PuTTy SSH per Windows o macOS
  • Powershell per Windows 10/11
  • Familiarità con i comandi APT

Proteggi Nginx con Let's Encrypt su Ubuntu 20.04

Passaggio 1. Innanzitutto, prima di iniziare a installare qualsiasi pacchetto sul tuo server Ubuntu, ti consigliamo sempre di assicurarti che tutti i pacchetti di sistema siano aggiornati.

sudo apt update
sudo apt upgrade

Nota:prima di installare il dominio SSL Let's Encrypt dovrebbe essere ben accessibile e utilizzare l'host virtuale Nginx. Leggi il tutorial su come installare Nginx su Ubuntu.

Passaggio 2. Installa Certbot.

Certbot è uno strumento completo e facile da usare che automatizza le attività per ottenere e rinnovare i certificati SSL Let's Encrypt e configurare i server Web per utilizzare i certificati . Per installarlo esegui i seguenti comandi:

sudo apt install certbot

Dopodiché, genera un nuovo set di parametri DH a 2048 bit digitando il seguente comando:

sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

Il server Let's Encrypt effettua richieste HTTP al file temporaneo per verificare che il dominio richiesto venga risolto nel server in cui viene eseguito certbot. Per semplificare, mapperemo tutte le richieste HTTP per .well-known/acme-challenge in una singola directory, /var/lib/letsencrypt :

sudo mkdir -p /var/lib/letsencrypt/.well-known
sudo chgrp www-data /var/lib/letsencrypt
sudo chmod g+s /var/lib/letsencrypt

Quindi, crea i seguenti due snippet che saranno inclusi in tutti i file di blocco del server Nginx:

sudo nano /etc/nginx/snippets/letsencrypt.conf
location ^~ /.well-known/acme-challenge/ {
  allow all;
  root /var/lib/letsencrypt/;
  default_type "text/plain";
  try_files $uri =404;
}

Quindi, crea il secondo snippet, ssl.conf:

sudo nano /etc/nginx/snippets/ssl.conf
ssl_dhparam /etc/ssl/certs/dhparam.pem;

ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers on;

ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 30s;

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;

Successivamente, apri il file di blocco del server di dominio e includi il letsencrypt.conf:

sudo nano /etc/nginx/sites-available/example.com.conf
server {
  listen 80;
  server_name example.com www.example.com;

  include snippets/letsencrypt.conf;
}

Non dimenticare di creare un collegamento simbolico dal file alla directory dei siti abilitati:

sudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/
sudo systemctl restart nginx

Una volta terminato, esegui Certbot con il plugin webroot e ottieni i file del certificato SSL emettendo:

sudo certbot certonly --agree-tos --email [email protected] --webroot -w /var/lib/letsencrypt/ -d example.com -d www.example.com

Infine, passaggi, modifica il blocco del server di dominio come segue:

sudo nano /etc/nginx/sites-available/example.com.conf
server {
    listen 80;
    server_name www.example.com example.com;

    include snippets/letsencrypt.conf;
    return 301 https://$host$request_uri;
}

server {
    listen 443 ssl http2;
    server_name www.example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;
    include snippets/letsencrypt.conf;

    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl http2;
    server_name example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    include snippets/ssl.conf;
    include snippets/letsencrypt.conf;
}

Ricarica il servizio Nginx per rendere effettive le modifiche:

sudo systemctl reload nginx

Passaggio 3. Verifica dello stato del certificato.

Puoi assicurarti che Certbot abbia creato il tuo certificato SSL correttamente utilizzando il test del server SSL della società di sicurezza cloud Qualys. Apri il seguente link nel tuo browser web preferito, sostituendo your-domain.com con il tuo dominio di base:

https://www.ssllabs.com/ssltest/analyze.html?d=your-domain.com

Passaggio 4. Rinnova il certificato SSL Let's Encrypt

E infine, prova il rinnovo automatico:

sudo certbot renew --dry-run

Questo è tutto ciò che devi fare per installare SSL Let's Encrypt con Nginx su Ubuntu 20.04 Focal Fossa. Spero che tu possa trovare utile questo suggerimento rapido. Se hai domande o suggerimenti, sentiti libero di lasciare un commento qui sotto.


Ubuntu
  1. Come proteggere Nginx con Lets Encrypt su Ubuntu 20.04 / 18.04

  2. Proteggi Nginx con Let's Encrypt su Ubuntu 18.04 - Come farlo?

  3. Come proteggere Nginx con Letsencrypt su Ubuntu 20.04

  4. Come installare Elgg con Nginx su Ubuntu 18.04

  5. Come proteggere Nginx con Let's Encrypt su Ubuntu 20.04

Proteggi Nginx con Let's Encrypt SSL Certificate su Ubuntu 18.04

Come proteggere Nginx con Let's Encrypt certificato SSL

Come proteggere il server LEMP con Let's Encrypt Free SSL su Ubuntu 18.04 VPS

Come proteggere Apache con Let's Encrypt su CentOS 8

Come proteggere Nginx con Let's Encrypt su CentOS 8

Come proteggere Apache con Let's Encrypt su Ubuntu 20.04