GNU/Linux >> LINUX-Kenntnisse >  >> Ubuntu

So richten Sie das Let’s Encrypt SSL-Zertifikat mit Nginx unter Ubuntu 18.04 und Ubuntu 16.04 ein

Let’s Encrypt ist eine weithin bekannte Zertifizierungsstelle, die kostenlose X.509-SSL-Zertifikate für die TLS-Verschlüsselung bereitstellt. Es wurde im April 2016 gestartet.

Let’s Encrypt automatisiert den Prozess der Zertifikatserstellung, -validierung, -signierung, -implementierung und -erneuerung von Zertifikaten.

Derzeit werden Apache, Nginx, Plex und Haproxy für den automatisierten Prozess unterstützt.

Voraussetzungen

Bevor Sie fortfahren, richten Sie den LEMP-Stack ein, um Nginx auf Ihrem Ubuntu-System zu haben.

LESEN :So installieren Sie den LEMP-Stack unter Ubuntu 18.04

LESEN :So installieren Sie den LEMP-Stack unter Ubuntu 16.04

Certbot installieren

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

Um den Certbot-Client zu installieren, müssen wir Certbot PPA auf Ubuntu konfigurieren.

sudo apt update

sudo apt install -y software-properties-common

sudo add-apt-repository universe

sudo add-apt-repository ppa:certbot/certbot

sudo apt update

Installieren Sie jetzt den Certbot-Client.

sudo apt install -y certbot python-certbot-nginx

Erstellen Sie einen virtuellen Nginx-Host

Wir erstellen nun eine virtuelle Host-Konfigurationsdatei 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 $document_root$fastcgi_script_name;
   }
}

Erstellen Sie einen Dokumentenstamm für Ihre HTML-Dateien.

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

Ändern Sie die Berechtigung des Verzeichnisses.

sudo chown -R nginx:nginx /opt/nginx/

Platzieren Sie die Test-HTML-Datei 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 aktualisieren / ändern

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 SSL-Zertifikat von Let’s Encrypt

Verwenden Sie den Befehl certbot, um manuell ein Let’s Encrypt-Zertifikat zu erstellen.

sudo certbot --nginx

Folgen Sie der interaktiven Aufforderung und generieren Sie das erforderliche 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 address to receive notifications

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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 of Service

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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  << Subscribe 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  << Select domain to install Let's Encrypt SSL certificate
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 from 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-11-04. 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 verwenden wir dieselbe Konfigurationsdatei, die wir für die HTTP-Version der Website erstellt haben, um die Nicht-www-HTTP-Website zur WW-HTTPS-Umleitung durchzuführen.

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 SSL-Zertifikat von Let’s Encrypt

Überprüfen Sie das Let’s Encrypt-Zertifikat, indem Sie die HTTPS-Version Ihrer Website besuchen.

http://Ihre-http-Website

ODER

https://Ihre-https-Website

Sie sollten jetzt die HTTPS-Version Ihrer Website erhalten.

Let’s Encrypt 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

SSL-Zertifikat von Let’s Encrypt 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 integrierten Cron-Scheduler-Eintrags, der mit dem Certbot-Client geliefert wird. Dieser Cron-Job wird zweimal täglich ausgeführt, um ablaufende Zertifikate zu erneuern.

Sie können den Zertifikaterneuerungsprozess mit dem folgenden Befehl simulieren, um sicherzustellen, dass die Erneuerung reibungslos verläuft.

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.

Die obige Ausgabe bestätigt, dass die Erneuerung wie erwartet funktioniert.

Schlussfolgerung

Das ist alles. Ich hoffe, Sie haben gelernt, wie Sie das SSL-Zertifikat Let’s Encrypt mit Nginx unter Ubuntu 18.04 und Ubuntu 16.04 einrichten. Bitte teilen Sie uns Ihr Feedback im Kommentarbereich mit.


Ubuntu
  1. Sichern Sie Nginx mit Lets Encrypt auf Ubuntu 20.04

  2. So richten Sie Let’s Encrypt (Certbot) unter Ubuntu 20.04 ein

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

  4. So installieren Sie Let’s Encrypt auf Ubuntu 20.04 mit Apache

  5. So sichern Sie Nginx mit Let’s Encrypt unter Ubuntu 20.04

So installieren Sie Let’s Encrypt SSL für Nginx unter Ubuntu 18.04 LTS

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

So installieren Sie Apache mit Let’s Encrypt SSL unter Ubuntu 20.04 LTS

Sichern Sie Nginx mit Let’s Encrypt SSL-Zertifikat auf Ubuntu 18.04

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

So sichern Sie Nginx mit Let’s Encrypt unter Ubuntu 20.04