GNU/Linux >> Znalost Linux >  >> Debian

Jak nastavit Let's Encrypt SSL certifikát s Nginx na Debian 10 / Debian 9

Let’s Encrypt je certifikační autorita, která poskytuje bezplatné certifikáty SSL pro šifrování TLS a byla spuštěna v dubnu 2016.

Let’s Encrypt neposkytuje pouze certifikáty SSL; také automatizuje vytváření certifikátů, ověřování, podepisování, implementaci a obnovování certifikátů pro zabezpečené webové stránky.

V současnosti Let’s Encrypt podporuje automatickou instalaci certifikátů na Apache, Nginx, Plex a Haproxy.

Předpoklady

Než budete pokračovat dále, doporučuji vám nastavit zásobník LEMP ve vašem systému.

ČTĚTE: Jak nainstalovat LEMP Stack na Debian 10

ČTĚTE: Jak nainstalovat LEMP Stack na Debian 9

Nastavení Let's Encrypt SSL Certificate pomocí Nginx

Nainstalujte Certbot

Chcete-li vygenerovat certifikát pro svou doménu, měli byste mít terminálový přístup a klienta Certbot ACME. Klient Certbot zpracovává vydání certifikátu a instalaci bez prostojů.

Certbot je dostupný v základním úložišti Debianu. K instalaci tedy můžete použít níže uvedené příkazy.

sudo apt update

sudo apt install -y certbot python-certbot-nginx

Vytvořit virtuální hostitele

Nyní vytvoříme virtuálního hostitele pro doménu www.itzgeek.net.

Tento virtuální hostitel obsluhuje HTTP verzi vaší domény.
sudo nano /etc/nginx/conf.d/www.itzgeek.net.conf

Použijte níže uvedené informace.

server {
   server_name www.itzgeek.net;
   root /opt/nginx/www.itzgeek.net;

   location / {
       index index.html index.htm index.php;
   }

   access_log /var/log/nginx/www.itzgeek.net.access.log;
   error_log /var/log/nginx/www.itzgeek.net.error.log;

   location ~ \.php$ {
      include /etc/nginx/fastcgi_params;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /opt/nginx/www.itzgeek.net$fastcgi_script_name;
   }
}

Vytvořte kořen dokumentu pro uložení souborů HTML.

sudo mkdir -p /opt/nginx/www.itzgeek.net

Změňte oprávnění k adresáři.

sudo chown -R nginx:nginx /opt/nginx/www.itzgeek.net

Umístěte ukázkový soubor HTML do kořenového adresáře dokumentu vaší domény.

echo "This is a test site @ www.itzgeek.net" | sudo tee /opt/nginx/www.itzgeek.net/index.html

Restartujte službu Nginx.

sudo systemctl restart nginx

Vytvořit / aktualizovat záznam DNS

Otevřete svůj nástroj pro správu DNS nebo registrátora domény a vytvořte záznam A/CNAME pro doménu. Příklad:www.itzgeek.net.

Počkejte nějakou dobu, než se záznam rozšíří.

Zkontrolujte šíření DNS pomocí nástroje Nslookup sudo apt install -y dnsutils.

Nainstalujte Let's Encrypt Certificate

Pomocí příkazu certbot vytvořte certifikát Let’s Encrypt a nakonfigurujte Nginx, aby certifikát používal.

sudo certbot --nginx

Postupujte podle interaktivní výzvy a nainstalujte certifikát.

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]  << Enter Email ID

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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  << Agree to Terms and Conditions

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: Y  << Subscriber to Newsletter

Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: www.itzgeek.net
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 1  << Choose Site to Install Let's Encrypt
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for www.itzgeek.net
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/www.itzgeek.net.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  << Redirect HTTP to HTTPS
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/www.itzgeek.net.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://www.itzgeek.net

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

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/www.itzgeek.net/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/www.itzgeek.net/privkey.pem
   Your cert will expire on 2019-10-28. 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


Přesměrujte požadavky HTTP bez www na www HTTPS pomocí Nginx (volitelné)

Nyní nakonfigurujeme server Nginx tak, aby přesměroval provoz přicházející z webu bez www HTTP na web WW HTTPS, tj. http://itzgeek.net>> https://www.itzgeek.net .

Zde upravíme stejný konfigurační soubor, který jsme vytvořili pro HTTP verzi webu.

sudo nano /etc/nginx/conf.d/www.itzgeek.net.conf

Přidejte níže uvedené informace na konec souboru.

# Redirect NON-WWW HTTP to WWW HTTPS

server {
    if ($host = itzgeek.net) {
        return 301 https://www.itzgeek.net$request_uri;
    }


   server_name itzgeek.net;
    listen 80;
    return 404;

}

Restartujte službu Nginx.

sudo systemctl restart nginx

Ověřte certifikát Let's Encrypt

Na vašem webu ověřte certifikát Let’s Encrypt.

http://vaše-http-webové-stránky

NEBO

https://vaše-https-webové-stránky

Nyní byste měli získat HTTPS verzi svého webu.

Test certifikát SSL

Přejděte na níže uvedenou adresu URL a otestujte svůj certifikát SSL na případné problémy a hodnocení zabezpečení.

https://www.ssllabs.com/ssltest/analyze.html?d=www.itzgeek.net

Obnovení certifikátu Let's Encrypt

Certifikáty Let’s Encrypt mají platnost 90 dní a je velmi vhodné si certifikáty před vypršením platnosti obnovit. Díky vestavěné položce plánovače /etc/cron.d/certbot, která se spouští dvakrát denně a obnovuje certifikáty, kterým brzy vyprší platnost.

Doporučuji vám však spustit níže uvedený příkaz pro simulaci automatického obnovení vašeho certifikátu.

sudo certbot renew --dry-run

Výstup:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/www.itzgeek.net.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator nginx, Installer nginx
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for www.itzgeek.net
Waiting for verification...
Cleaning up challenges

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of nginx server; fullchain is
/etc/letsencrypt/live/www.itzgeek.net/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates below have not been saved.)

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/www.itzgeek.net/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - 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.

Pokud výstup potvrdí, že obnovení funguje správně, automatické obnovení proběhne podle očekávání.

Závěr

To je vše. Doufám, že jste se naučili, jak nastavit Let’s Encrypt SSL Certificate pomocí Nginx na Debianu 10. Podělte se o svůj názor v sekci komentářů.


Debian
  1. Jak nainstalovat Drupal 9 s Nginx a nechat šifrovat SSL na Debian 10

  2. Zabezpečte Nginx pomocí Let's Encrypt SSL na Debianu 10/11

  3. Jak nainstalovat Let's Encrypt SSL na Ubuntu 18.04 s Nginx

  1. Jak nainstalovat Wekan Kanban s Nginx a nechat šifrovat SSL na Debian 10

  2. Jak nastavit Zašifrujeme certifikát SSL pomocí Nginx na CentOS 8 / RHEL 8 &CentOS 7 / RHEL 7

  3. Jak nastavit Let's Encrypt SSL certifikát s Apache na CentOS 8 / RHEL 8 &CentOS 7 / RHEL 7

  1. Jak nainstalovat WordPress s Apache a Let's Encrypt SSL na Debian 11

  2. Jak nainstalovat Let’s Encrypt SSL v Apache na Debianu 11

  3. Jak nainstalovat Drupal s Nginx a zašifrovat SSL na Debian 11