GNU/Linux >> LINUX-Kenntnisse >  >> Panels >> Panels

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

Das Sichern einer Website, die mit Nginx als Webserver ausgeführt wird, kann mit Let’s Encrypt erfolgen, und deshalb schreiben wir dieses Tutorial für Sie.

Let’s Encrypt ist eine Zertifizierungsstelle, die kostenlose TLS/SSL-Zertifikate bereitstellt, die 90 Tage gültig sind. SSL steht für Secure Sockets Layer und ein SSL-Zertifikat ist ein digitales Zertifikat, das eine verschlüsselte Verbindung und Authentifizierung der Website-Identität ermöglicht. In diesem Blogbeitrag verwenden wir Certbot, um ein kostenloses SSL-Zertifikat für Nginx zu erhalten.

Die Installation des kostenlosen SSL-Zertifikats Let’s Encrypt auf Ubuntu 20.04 mit Certbot ist ein unkomplizierter Vorgang und sollte bis zu 10 Minuten dauern. Fangen wir an!

Voraussetzungen

  • Neuinstallation von Ubuntu 20.04
  • Benutzerberechtigungen:Root- oder Nicht-Root-Benutzer mit sudo-Berechtigungen
  • Gültig Eine Aufzeichnung der Domain, die auf die IP-Adresse Ihres Servers verweist (IhreDomain.com und www.IhreDomain.com)

System aktualisieren

Bevor wir mit dem Installationsprozess beginnen, müssen wir das System aktualisieren, um die neuesten verfügbaren Pakete und Updates zu erhalten.

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

Nginx-Webserver installieren

Um den Nginx-Webserver zu installieren, führen Sie die folgenden Befehle aus:

sudo apt install nginx -y

Sobald die Installation abgeschlossen ist, aktivieren und starten Sie den Nginx-Dienst:

sudo systemctl enable nginx && sudo systemctl start nginx

Um zu überprüfen, ob alles in Ordnung ist, überprüfen Sie den Status des Dienstes:

sudo systemctl status nginx

Sie sollten die folgende Ausgabe erhalten:

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;

Erstellen Sie einen virtuellen Nginx-Host

Bevor wir mit der Installation von Free Let’s Encrypt fortfahren, müssen wir eine virtuelle Hostdatei erstellen, die unseren Domainnamen enthält. Gehen Sie in das Nginx-Konfigurationsverzeichnis und erstellen Sie die Datei.

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

Fügen Sie die folgenden Codezeilen ein.

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

Überprüfen Sie die Nginx-Konfigurationssyntax, wenn sie in Ordnung ist.

nginx -t

Sie sollten die folgende Ausgabe erhalten:

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

Wenn Sie diese Ausgabe erhalten, können Sie den Nginx-Dienst neu starten und auf Ihre Website zugreifen.

sudo systemctl restart nginx

Certbot installieren

Derzeit läuft unsere Website über das HTTP-Protokoll. Durch die Installation des kostenlosen SSL-Zertifikats Let’s Encrypt wird unsere Website sicher über das HTTPS-Protokoll ausgeführt. Bevor wir mit dem Erhalt des Zertifikats beginnen, müssen wir den Python-Certbot für Nginx installieren.

sudo apt install certbot python3-certbot-nginx

Sobald der Certbot erfolgreich installiert ist, können wir mit dem Hauptschritt in diesem Tutorial zum Erhalt eines SSL-Zertifikats fortfahren.

Ein SSL-Zertifikat erhalten

Führen Sie den folgenden Befehl aus, um den Certbot mit dem Nginx-Plugin auszuführen, das den Namen Ihrer Domäne angibt:

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

Nachdem Sie diesen Befehl ausgeführt haben, müssen Sie einige Einträge ausfüllen, z. B. die E-Mail-Adresse, die Zustimmung zu den Allgemeinen Geschäftsbedingungen, ob Sie Ihre E-Mail-Adresse teilen möchten oder nicht und die Weiterleitungsoptionen.

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

Wenn alles so eingerichtet ist, wie es sein sollte, wird das Zertifikat installiert und Sie erhalten die folgende Meldung.

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

Jetzt können Sie unter https://yourdomain.com sicher auf Ihre Website zugreifen

Herzliche Glückwünsche! Sie haben Nginx erfolgreich mit dem kostenlosen Let’s Encrypt SSL-Zertifikat auf Ihrem Ubuntu 20.04-Server gesichert.

Natürlich müssen Sie das SSL-Zertifikat nicht selbst installieren, und wenn Sie einen unserer SSD-VPS-Hosting-Dienste nutzen, können Sie in diesem Fall einfach unsere erfahrenen Systemadministratoren bitten, es für Sie zu installieren und Ihre Website zu sichern. Sie sind rund um die Uhr erreichbar und kümmern sich umgehend um Ihr Anliegen.

Wenn Ihnen dieser Beitrag über die Sicherung von Nginx mit Lets Encrypt unter Ubuntu 20.04 gefallen hat, teilen Sie ihn bitte mit Ihren Freunden in den sozialen Netzwerken über die Schaltflächen unten oder hinterlassen Sie einfach einen Kommentar im Kommentarbereich. Danke.


Panels
  1. Sichern Sie Nginx mit Let’s Encrypt auf Ubuntu 18.04 – wie geht das?

  2. So sichern Sie Nginx mit Letsencrypt unter Ubuntu 20.04

  3. So installieren Sie Elgg mit Nginx unter Ubuntu 14.04

  4. So installieren Sie Elgg mit Nginx unter Ubuntu 18.04

  5. So installieren Sie Joomla mit Nginx unter Ubuntu 18.04

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

So sichern Sie den LEMP-Server mit Let’s Encrypt Free SSL auf Ubuntu 18.04 VPS

So sichern Sie Apache mit Let’s Encrypt unter CentOS 8

So sichern Sie Nginx mit Let’s Encrypt unter CentOS 8

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

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