GNU/Linux >> Linux Esercitazione >  >> Panels >> Panels

Come proteggere Nginx con Let's Encrypt su Ubuntu 20.04

La protezione di un sito Web in esecuzione con Nginx come server Web può essere eseguita con Let's Encrypt, ed è per questo che stiamo scrivendo questo tutorial per te.

Let's Encrypt è un'autorità di certificazione che fornisce certificati TLS/SSL gratuiti validi per 90 giorni. SSL sta per Secure Sockets Layer e un certificato SSL è un certificato digitale che consente la connessione crittografata e l'autenticazione dell'identità del sito web. In questo post del blog, utilizzeremo Certbot per ottenere un certificato SSL gratuito per Nginx.

L'installazione del certificato SSL Let's Encrypt gratuito su Ubuntu 20.04 con Certbot è un processo semplice e dovrebbe richiedere fino a 10 minuti. Iniziamo!

Prerequisiti

  • Nuova installazione di Ubuntu 20.04
  • Privilegi utente:utente root o non root con privilegi sudo
  • Valido Un record del dominio puntato all'indirizzo IP del tuo server (tuodominio.com e www.tuodominio.com)

Aggiorna il sistema

Prima di iniziare con il processo di installazione, è necessario aggiornare il sistema per ottenere gli ultimi pacchetti e aggiornamenti disponibili.

sudo apt update -y && sudo apt upgrade -y

Installa Nginx Web Server

Per installare il server web Nginx eseguire i seguenti comandi:

sudo apt install nginx -y

Una volta completata l'installazione, abilita e avvia il servizio Nginx:

sudo systemctl enable nginx && sudo systemctl start nginx

Per verificare se tutto è a posto, controlla lo stato del servizio:

sudo systemctl status nginx

Dovresti ricevere il seguente output:

root@vps:~# systemctl status nginx
● nginx.service - A high performance web server and a reverse proxy server
     Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2022-02-06 19:34:56 UTC; 11s ago
       Docs: man:nginx(8)
    Process: 322857 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
    Process: 322858 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
   Main PID: 322859 (nginx)
      Tasks: 5 (limit: 4617)
     Memory: 5.0M
     CGroup: /system.slice/nginx.service
             ├─322859 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;

Crea host virtuale Nginx

Prima di continuare con l'installazione di Free Let's Encrypt, dobbiamo creare un file host virtuale contenente il nostro nome di dominio. Vai nella directory di configurazione di Nginx e crea il file.

cd /etc/nginx/conf.d/ && sudo nano yourdomain.com.conf

Incolla le seguenti righe di codice.

server {
        listen 80;
        root /var/www/html;
        index  index.php index.html index.htm;
        server_name yourdomain.com;

        error_log /var/log/nginx/yourdomain.com_error.log;
        access_log /var/log/nginx/yourdomain.com_access.log;

        client_max_body_size 100M;
        location / {
                try_files $uri $uri/ /index.php?$args;
        }
}

Controlla la sintassi di configurazione di Nginx se è OK.

nginx -t

Dovresti ricevere il seguente output:

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

Se ricevi questo output puoi riavviare il servizio Nginx e accedere al tuo sito web.

sudo systemctl restart nginx

Installa Certbot

In questo momento, il nostro sito Web è in esecuzione sul protocollo HTTP. L'installazione del certificato SSL Let's Encrypt gratuito consentirà al nostro sito Web di funzionare in modo sicuro tramite il protocollo HTTPS. Prima di iniziare con l'ottenimento del certificato, è necessario installare python certbot per Nginx.

sudo apt install certbot python3-certbot-nginx

Una volta che il certbot è stato installato correttamente, possiamo procedere con il passaggio principale di questo tutorial sull'ottenimento di un certificato SSL.

Come ottenere un certificato SSL

Per eseguire il certbot con il plugin Nginx specificando il nome del tuo dominio esegui il seguente comando:

sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com

Dopo aver eseguito questo comando ci saranno un paio di voci che dovrai compilare, come l'indirizzo e-mail, l'accordo sui termini e le condizioni, se desideri condividere o meno il tuo indirizzo e-mail e le opzioni di reindirizzamento.

root@vps:~# sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: N
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for yourdomain.com
http-01 challenge for www.yourdomain.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/example.conf
Deploying Certificate to VirtualHost /etc/nginx/conf.d/example.conf

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/example.conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/example.conf

Se tutto è impostato come dovrebbe essere, il certificato verrà installato e riceverai il messaggio qui sotto.

Congratulations! You have successfully enabled https://yourdomain.com and
https://www.yourdomain.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=yourdomain.com
https://www.ssllabs.com/ssltest/analyze.html?d=www.yourdomain.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/yourdomain.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/yourdomain.com/privkey.pem
   Your cert will expire on 2022-05-07. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - 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

Ora puoi accedere al tuo sito web in modo sicuro su https://tuodominio.com

Congratulazioni! Hai protetto con successo Nginx con il certificato SSL gratuito Let's Encrypt sul tuo server Ubuntu 20.04.

Ovviamente non devi installare il certificato SSL da solo e se utilizzi uno dei nostri servizi di Hosting SSD VPS, in tal caso puoi semplicemente chiedere ai nostri esperti amministratori di sistema di installarlo per te e proteggere il tuo sito web. Sono disponibili 24 ore su 24, 7 giorni su 7 e si prenderanno immediatamente cura della tua richiesta.

Se ti è piaciuto questo post, su come proteggere Nginx con Lets Encrypt su Ubuntu 20.04, condividilo con i tuoi amici sui social network usando i pulsanti qui sotto o lascia semplicemente un commento nella sezione commenti. Grazie.


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

  2. Come proteggere Nginx con Letsencrypt su Ubuntu 20.04

  3. Come installare Elgg con Nginx su Ubuntu 14.04

  4. Come installare Elgg con Nginx su Ubuntu 18.04

  5. Come installare Joomla con Nginx 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 Nginx con Let's Encrypt su Ubuntu 20.04

Come proteggere Apache con Let's Encrypt su Ubuntu 20.04