GNU/Linux >> LINUX-Kenntnisse >  >> Debian

So richten Sie ein SSL-Zertifikat von Let’s Encrypt mit Nginx unter Debian 10 / Debian 9 ein

Let’s Encrypt ist eine Zertifizierungsstelle, die kostenlose SSL-Zertifikate für die TLS-Verschlüsselung anbietet und im April 2016 eingeführt wurde.

Let’s Encrypt bietet nicht nur SSL-Zertifikate; Es automatisiert auch die Zertifikatserstellung, -validierung, -signierung, -implementierung und -erneuerung von Zertifikaten für sichere Websites.

Derzeit unterstützt Let’s Encrypt die automatische Installation von Zertifikaten auf Apache, Nginx, Plex und Haproxy.

Voraussetzungen

Ich empfehle Ihnen, den LEMP-Stack auf Ihrem System einzurichten, bevor Sie fortfahren.

LESEN: So installieren Sie den LEMP-Stack unter Debian 10

LESEN: So installieren Sie den LEMP-Stack unter Debian 9

Let’s Encrypt SSL-Zertifikat mit Nginx einrichten

Certbot installieren

Um ein Zertifikat für Ihre Domain zu generieren, sollten Sie Terminalzugriff und den Certbot ACME-Client haben. Der Certbot-Client verarbeitet die Ausstellung und Installation von Zertifikaten ohne Ausfallzeit.

Certbot ist im Debian-Basis-Repository verfügbar. Sie können also die folgenden Befehle verwenden, um es zu installieren.

sudo apt update

sudo apt install -y certbot python-certbot-nginx

Virtualhost erstellen

Wir erstellen nun einen virtuellen Host für die Domain www.itzgeek.net.

Dieser virtuelle Host bedient die HTTP-Version Ihrer Domain.
sudo nano /etc/nginx/conf.d/www.itzgeek.net.conf

Verwenden Sie die folgenden Informationen.

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;
   }
}

Erstellen Sie einen Dokumentenstamm, um HTML-Dateien aufzunehmen.

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

Ändern Sie die Berechtigung des Verzeichnisses.

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

Platzieren Sie die HTML-Beispieldatei im Dokumentenstammverzeichnis Ihrer Domain.

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

Starten Sie den Nginx-Dienst neu.

sudo systemctl restart nginx

DNS-Eintrag erstellen/aktualisieren

Greifen Sie auf Ihr DNS-Verwaltungstool oder Ihren Domain-Registrar zu und erstellen Sie einen A/CNAME-Eintrag für die Domain. Beispiel:www.itzgeek.net.

Warten Sie einige Zeit, bis der Datensatz weitergegeben wird.

Überprüfen Sie die DNS-Weitergabe mit dem Dienstprogramm Nslookup sudo apt install -y dnsutils.

Installieren Sie das Let’s Encrypt-Zertifikat

Verwenden Sie den Befehl certbot, um ein Let’s Encrypt-Zertifikat zu erstellen, und konfigurieren Sie Nginx für die Verwendung des Zertifikats.

sudo certbot --nginx

Folgen Sie der interaktiven Aufforderung und installieren Sie das Zertifikat.

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


Nicht-www-HTTP-Anforderungen mit Nginx an www-HTTPS umleiten (optional)

Wir werden jetzt den Nginx-Server so konfigurieren, dass er den Datenverkehr von HTTP-Sites ohne www auf die WW-HTTPS-Site umleitet, d. h. http://itzgeek.net>> https://www.itzgeek.net .

Hier bearbeiten wir dieselbe Konfigurationsdatei, die wir für die HTTP-Version der Website erstellt haben.

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

Fügen Sie die folgenden Informationen am Ende der Datei hinzu.

# 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;

}

Starten Sie den Nginx-Dienst neu.

sudo systemctl restart nginx

Verifizieren Sie das Let’s Encrypt-Zertifikat

Verifizieren Sie das Let’s Encrypt-Zertifikat, indem Sie Ihre Website besuchen.

http://Ihre-http-Website

ODER

https://Ihre-https-Website

Sie sollten jetzt die HTTPS-Version Ihrer Website erhalten.

SSL-Zertifikat testen

Testen Sie Ihr SSL-Zertifikat auf Probleme und seine Sicherheitsbewertungen, indem Sie zur folgenden URL gehen.

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

Let’s Encrypt-Zertifikat erneuern

Zertifikate von Let’s Encrypt haben eine Gültigkeit von 90 Tagen, und es wird dringend empfohlen, Ihre Zertifikate zu erneuern, bevor sie ablaufen. Dank des eingebauten Scheduler-Eintrags /etc/cron.d/certbot, der zweimal täglich ausgeführt wird, um Zertifikate zu erneuern, die bald ablaufen.

Ich empfehle Ihnen jedoch, den folgenden Befehl auszuführen, um die automatische Erneuerung Ihres Zertifikats zu simulieren.

sudo certbot renew --dry-run

Ausgabe:

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.

Wenn die Ausgabe bestätigt, dass die Verlängerung ordnungsgemäß funktioniert, erfolgt die automatische Verlängerung wie erwartet.

Schlussfolgerung

Das ist alles. Ich hoffe, Sie haben gelernt, wie man ein SSL-Zertifikat von Let’s Encrypt mit Nginx unter Debian 10 einrichtet. Teilen Sie Ihr Feedback im Kommentarbereich mit.


Debian
  1. So installieren Sie Drupal 9 mit Nginx und Lets Encrypt SSL unter Debian 10

  2. So installieren Sie Wekan Kanban mit Nginx und Lets Encrypt SSL unter Debian 10

  3. So richten Sie ein SSL-Zertifikat von Let’s Encrypt mit Nginx unter CentOS 8 / RHEL 8 und CentOS 7 / RHEL 7 ein

  4. Sichern Sie Nginx mit Let’s Encrypt SSL auf Debian 10/11

  5. So installieren Sie Let’s Encrypt SSL auf Ubuntu 18.04 mit Nginx

Installieren und konfigurieren Sie Webmin mit dem kostenlosen Let’s Encrypt SSL-Zertifikat auf Debian 10

So richten Sie Let’s Encrypt SSL mit Apache auf Fedora ein

So installieren Sie Nginx mit Let’s Encrypt TLS/SSL unter Debian 11 Bullseye

So installieren Sie Nginx mit Let’s Encrypt TLS/SSL unter Ubuntu 20.04

So installieren Sie Nginx mit Let’s Encrypt SSL auf Fedora 35

So sichern Sie Nginx mit dem Let’s Encrypt SSL-Zertifikat