GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Come installare Let's Encrypt SSL con Nginx su Ubuntu 16.04 LTS

In questo tutorial, ti mostreremo come installare Let's Encrypt SSL con Nginx su Ubuntu 16.04 LTS. Per chi non lo sapesse, LetsEncrypt è un'autorità di certificazione aperta gratuita (CA ) che fornisce certificati gratuiti per siti Web e altri servizi. Il servizio è supportato da Electronic Frontier Foundation, Mozilla, Cisco Systems e Akamai. Sfortunatamente, i certificati LetsEncrypt.org hanno attualmente una durata di 3 mesi. Ciò significa che dovrai rinnova il tuo certificato trimestralmente per ora.

Questo articolo presuppone che tu abbia almeno una conoscenza di base di Linux, sappia come usare la shell e, soprattutto, che ospiti il ​​tuo sito sul tuo VPS. L'installazione è abbastanza semplice e presuppone che tu sono in esecuzione nell'account root, in caso contrario potrebbe essere necessario aggiungere 'sudo ' ai comandi per ottenere i privilegi di root. Ti mostrerò l'installazione passo passo Let's Encrypt SSL con Nginx su un server Ubuntu 16.04 LTS (Xenial Xerus).

Prerequisiti

  • Un server che esegue uno dei seguenti sistemi operativi:Ubuntu 16.04 LTS (Xenial Xerus).
  • Si consiglia di utilizzare una nuova installazione del sistema operativo per prevenire potenziali problemi.
  • Accesso SSH al server (o semplicemente apri Terminal se sei su un desktop).
  • Un non-root sudo user o accedere all'root user . Ti consigliamo di agire come non-root sudo user , tuttavia, poiché puoi danneggiare il tuo sistema se non stai attento quando agisci come root.

Installa Let's Encrypt SSL con Nginx su Ubuntu 16.04 LTS

Passaggio 1. Innanzitutto, assicurati che tutti i pacchetti di sistema siano aggiornati eseguendo il seguente apt-get comandi nel terminale.

sudo apt-get update
sudo apt-get upgrade

Passaggio 2. Installazione di Let's Encrypt SSL su Ubuntu 16.04.

Il primo passo è installare certbot, il client software che automatizzerà quasi tutto nel processo:

add-apt-repository ppa:certbot/certbot
apt-get update
apt-get install certbot

Dovrai anche avere Nginx installato e in esecuzione. Ovviamente, se stai aggiungendo certificati a un host web precedentemente configurato, questo sarebbe già installato:

apt-get install nginx
systemctl start nginx

Il primo passo per installare Let's encrypt SSL su Ubuntu Linux è aggiungere una semplice configurazione all'interno della configurazione del blocco del server Nginx. Aggiungi questa riga alla configurazione del blocco del server:

location ~ /.well-known {
  allow all;
  }

Salva ed esci per applicare le modifiche:

### nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Riavvia Nginx:

systemctl restart nginx

Come ottenere un certificato con Certbot:

Esegui il comando come vedi sotto, sostituisci “idroot.us” con il tuo vero nome di dominio e /var/www/idroot.us con il tuo vero percorso webroot:

certbot certonly -a webroot --webroot-path=/var/www/idroot.us -d idroot.us -d www.idroot.us

Risultato:

[[email protected]:~]certbot certonly -a webroot --webroot-path=/var/www/idroot.us -d idroot.us -d www.idroot.us
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for idroot.us
Using the webroot path /var/www/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges
Generating key (2048 bits): /etc/letsencrypt/keys/0001_key-certbot.pem
Creating CSR: /etc/letsencrypt/csr/0001_csr-certbot.pem
IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/idroot.us/fullchain.pem. Your cert
   will expire on 2017-07-16. To obtain a new or tweaked version of
   this certificate in the future, simply run certbot again. To
   non-interactively renew *all* of your certificates, run "certbot
   renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le
[[email protected]:~]

Passaggio 3. Configura SSL/TLS sul server web NGINX.

Per prima cosa, modifica il file di blocco del server specificato durante la configurazione tramite Certbot e aggiungi queste tre direttive:

listen 443 ssl http2;
ssl_certificate /etc/letsencrypt/live/idroot.us/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/idroot.us/privkey.pem;

La configurazione completa del blocco del server Nginx potrebbe essere simile a questa:

server {
     listen 80;
     server_name idroot.us www.idroot.us;
     rewrite ^(.*) https://idroot.us$1 permanent;
}
server {
     access_log off;
     log_not_found off;
     error_log  logs/idroot.us-error_log warn;

    server_name  idroot.us; 
    root   /var/www/idroot.us;
    index  index.php index.html index.htm;

    listen 443 ssl http2;
    ssl_certificate /etc/letsencrypt/live/idroot.us/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/idroot.us/privkey.pem;

  ## Stuff required by certbot
     location ~ /.well-known {
     allow all;
     }

  ## SSL
   ssl_session_cache shared:SSL:20m;
   ssl_session_timeout 10m;

   ssl_prefer_server_ciphers On;
   ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
   ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS;

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

   access_log /var/www/idroot.us/logs/access.log;
   error_log /var/www/idroot.us/logs/error.log;

   # php-script handler
   location ~ \.php$ {
      fastcgi_index index.php;
      fastcgi_pass 127.0.0.1:9000;       fastcgi_read_timeout 150;
      root    /var/www/idroid.us/public_html;
      fastcgi_param SCRIPT_FILENAME /var/www/idroot.us$fastcgi_script_name;
      include /etc/nginx/fastcgi_params;
   }
 location  ~ /\.ht {
               deny  all;
           }
    }

Salva e chiudi il file quando hai finito.

Passaggio 5. Configura Let's Encrypt SSL Rinnovo automatico.

Aggiungeremo un cronjob per eseguire il comando di rinnovo ogni settimana, esegui questo comando:

export VISUAL=nano; crontab -e

Incolla le seguenti righe:

01 1 * * 0 /usr/bin/certbot renew >> /var/log/ssl-renew.log 
06 1 * * 0 /usr/bin/systemctl nginx reload

Salva ed esci dalla tabella crontab.

Questo creerà un nuovo lavoro cron che verrà eseguito ogni domenica alle 01:00, quindi ricaricherà il server web Nginx per applicare le modifiche. L'output sarà effettuato l'accesso a /var/log/ssl-renew.log file per ulteriori analisi, se necessario.

Congratulazioni! Hai installato con successo Let's Encrypt. Grazie per aver utilizzato questo tutorial per l'installazione di Let's Encrypt SSL sul sistema LTS di Ubuntu 16.04. Per ulteriore aiuto o informazioni utili, ti consigliamo di controllare il Let's Encrypt ufficiale sito web.


Ubuntu
  1. Come installare Nextcloud con Nginx e Lets Encrypt SSL su Ubuntu 20.04 LTS

  2. Come installare Magento 2 con Nginx e Lets Encrypt SSL su Ubuntu 20.04 LTS

  3. Come installare Seafile con Nginx su Ubuntu 20.04 LTS

  4. Come distribuire Modsecurity con Nginx su Ubuntu 20.04 LTS

  5. Come installare Let's Encrypt SSL su Ubuntu 18.04 con Nginx

Come installare Nginx con Let's Encrypt TLS/SSL su Ubuntu 20.04

Come installare Let's Encrypt SSL con Nginx su CentOS 7

Come installare Let's Encrypt SSL per Nginx su Ubuntu 18.04 LTS

Come installare phpMyAdmin con Nginx su Ubuntu 20.04 LTS

Come installare Nginx con Let's Encrypt SSL su Ubuntu 20.04 LTS

Come installare Apache con Let's Encrypt SSL su Ubuntu 20.04 LTS