Möchten Sie lernen, wie Sie Ihre Apache-Website vor der Verwendung des kostenlosen HTTP-Zertifikats schützen können? In diesem Lernprogramm zeigen wir Ihnen alle Schritte, die zum Sichern von Apache mit Let's Encrypt unter Ubuntu Linux erforderlich sind

• Ubuntu-Version: 18.04

Zur Veranschaulichung der Installation verwenden wir eine unserer Domänen mit dem Namen MINING-POOL.NINJA.

Sie müssen die Konfigurationsdateien ändern und unseren Domainnamen MINING-POOL.NINJA durch Ihren Domainnamen ersetzen.

Hardware-Liste:

Der folgende Abschnitt enthält eine Liste der Geräte, die zum Erstellen dieses WordPress-Lernprogramms verwendet werden.

Alle oben aufgeführten Hardwarekomponenten finden Sie auf der Amazon-Website.

Apache-bezogenes Tutorial:

Auf dieser Seite bieten wir schnellen Zugriff auf eine Liste von Tutorials zu Apache.

1. Erwerben Sie einen Domainnamen

Zuerst müssen Sie auf das zugreifen GODADDY und ein Konto erstellen.

Dieses Konto wird zum Kauf einer DNS-Domäne verwendet.

In unserem Beispiel erwerben wir die Domäne MINING-POOL.NINJA.

Sie können jede Website verwenden, um eine DNS-Domäne zu erwerben.

GoDaddy ist nur meine Lieblingswahl.

2. Konfigurieren Sie einen DNS-Eintrag

Jetzt müssen Sie eine DNS-Registrierung konfigurieren, die auf Ihren Apache-Webserver verweist.

Nach dem Kauf einer DNS-Domäne müssen Sie einen DNS-Eintrag erstellen, der Ihre Website-Adresse auf den Computer mit Ubuntu Linux verweist.

In unserem Beispiel haben wir einen DNS-Eintrag erstellt, der die Domäne MINING-POOL.NINJA auf die IP-Adresse 35.163.100.49 verweist.

HTTPS DNS Entry

Verwenden Sie die folgenden Befehle, um Ihre DNS-Konfiguration auf einem Computer unter Linux zu testen.

# apt-get update
# apt-get install dnsutils
# nslookup mining-pool.ninja

Non-authoritative answer:
Name: mining-pool.ninja
Address: 35.163.100.49

Der obige Befehl hat bestätigt, dass die Domäne auf die IP-Adresse 35.163.100.49 verweist.

3. Installieren Sie den Apache-Webserver

Die Zertifizierungsstelle Let's Encrypt setzt voraus, dass der Benutzer über einen voll funktionsfähigen Apache-Webserver verfügt.

Wir müssen den Apache-Webserver und die gesamte erforderliche Software installieren.

Verwenden Sie in der Linux-Konsole die folgenden Befehle, um die erforderlichen Pakete zu installieren.

# apt-get update
# apt-get install apache2 php7.2 php7.2-mysql libapache2-mod-php7.2
# apt-get install openssl

Aktivieren Sie den Apache mod_rewrite und bearbeiten Sie die Datei apache2.conf.

# a2enmod rewrite
# vi /etc/apache2/apache2.conf

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

<Directory /var/www/html>
AllowOverride All
</Directory>

Erstellen Sie eine Apache Virtualhost-Konfigurationsdatei für Ihre Website.

# vi /etc/apache2/sites-available/mining-pool.conf

Denken Sie daran, dass der Name und der Speicherort Ihrer Virtualhost-Datei möglicherweise nicht mit meinem übereinstimmt.

Als Beispiel ist hier der Inhalt unserer Datei:

<VirtualHost *:80>
ServerAdmin nobody@care.com
DocumentRoot /websites/www
ServerName mining-pool.ninja

<Directory /websites/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/logs/error.log
CustomLog /websites/logs/access.log combined
LogLevel error
</VirtualHost>

Erstellen Sie die Liste der erforderlichen Ordner.

Stellen Sie die korrekte Dateiberechtigung für alle Ordner ein.

Denken Sie daran, dass Ihr Ordnerspeicherort möglicherweise nicht mit dem meines übereinstimmt.

# mkdir /websites
# cd /websites
# mkdir www logs
# chown www-data.www-data /websites -R

Aktivieren Sie Ihre Apache Virtualhost-Konfiguration und starten Sie den Apache-Dienst neu.

# a2ensite mining-pool.conf
# systemctl reload apache2

4. Konfigurieren Sie das kostenlose HTTPS-Zertifikat für Apache

Verwenden Sie in der Linux-Konsole den folgenden Befehl, um die erforderlichen Pakete zu installieren.

# apt-get install software-properties-common
# add-apt-repository universe
# add-apt-repository ppa:certbot/certbot
# apt-get update
# apt-get install python-certbot-apache

Für das Certbot-Skript muss der Benutzer über einen voll funktionsfähigen Apache-Webserver verfügen.

Die Installation und Konfiguration von Apache Virtualhost ist bereits abgeschlossen.

Verwenden Sie die folgende Befehlsanforderung, und installieren Sie das Apache free HTTPS-Zertifikat.

Denken Sie daran, dass Ihr Domainname nicht mit meinem identisch sein sollte.

# certbot --apache -d mining-pool.ninja

• Drücken Sie (A), um die Nutzungsbedingungen zu akzeptieren.
• Drücken Sie (J), um Ihre E-Mail zu teilen und Newsletter zu erhalten.
• Drücken Sie (2), um Ihre HTTP-Website automatisch zu den HTTPS-Versionen umzuleiten.

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): techexpert.tips@gmail.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mining-pool.ninja
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/mining-pool-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/mining-pool-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/mining-pool-le-ssl.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
Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/mining-pool.conf to ssl vhost in /etc/apache2/sites-available/mining-pool-le-ssl.conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://mining-pool.ninja

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

IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/mining-pool.ninja/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/mining-pool.ninja/privkey.pem
Your cert will expire on 2019-03-19. 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"
- 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

Das System fordert das Zertifikat automatisch an und konfiguriert Ihren Apache-Webserver so, dass der gesamte HTTP-Zugriff auf die HTTPS-Version Ihrer Website umgeleitet wird.

In unserem Beispiel hat das System eine HTTPS Virtualhost-Konfigurationsdatei mit dem Namen mining-pool-le-ssl.conf erstellt

Hier ist der Inhalt der HTTPS Virtualhost-Konfigurationsdatei mining-pool-le-ssl.conf:

<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin nobody@care.com
DocumentRoot /websites/www
ServerName mining-pool.ninja

<Directory /websites/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/logs/error.log
CustomLog /websites/logs/access.log combined
LogLevel error

SSLCertificateFile /etc/letsencrypt/live/mining-pool.ninja/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mining-pool.ninja/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Die KEY-Datei enthält Ihren privaten Zertifikatschlüssel und muss immer an einem sicheren Ort aufbewahrt werden.

Hier ist der Inhalt der KEY-Datei: /etc/letsencrypt/live/mining-pool.ninja/privkey.pem

-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCwGYFx4kcQmYC5
gJftnjZhWNVZkIL7wSMTFtFfIY37PNbVNeJ11HoudX8HWout8qXOxBvHE8oUtzrO
/956cCVNsdY+eXZVVwUhjeSRT9wH2vUh3vVw6mi0TRy1KZJGo+hFeUS7zGb0/IwV
MofsEE3rAM1s9RoNOzH6Q/S7OiXFH4OhjbORcv0mBBDjbUgIB+PPoSdCj98yHjZN
vyVEvU9xZLQZxDfFMJr9lNAOR0AIOaALkXaMu1zC5+G1Z2x+W9xSI4JMegiKoHhI
/Xt3A3lCyT81GGc3RrmlighZZVstr0FK4XotcJe5YLsBn1xIukyUrWnJHGRz8MmC
26ShYRLLAgMBAAECggEAdpK19ljGQQcbBczwf67oLuQBxCzqBVomo9PZZpTRZTmx
7h46Pdyz6FR1FB6DrryTqIWjrohEqW42yuq+gvLAK3BzMd3XL99INS+1l6KOJTvp
ksTtvvoXRlAl5FX5iFcVLrJY9ZrMOGlUaXF81BamYHZJ2/OtdvtEy562Str8U52m
GTkgfpWnaLc66T05zViNwiAb5yg0v9Xb9YOEgLY8VdqYppUnJNzYs7utiDGbOjPa
OCZ5oLTl1b9l6sNw7RhhOmq/jPOur4Keg124fyleULi2Uln52waLWeI8fWI/AHmP
UQQkC3athEOKr0f1Zk9ZRxYJq5FYGPTElqQdbltEAQKBgQDiqSp4XM0tfFJwZIkH
ooEcPw+to4T0333K4mipx+YxlELCHvIXW2xIxlejyhgnVIQWX6qS0F7VUGnVuSKz
hB0zfcd89MYcqGyQSEdc9kZB+Twb9Hzd3fTXu7hKjXoz9+UKfcOXfQdILGnDqyG8
zCF//aNocRvxaO9E1cZ+1irlcQKBgQDG5OZUr8kMYI8Tl0GcmWZSFZfMYBYT3CAq
YPHmNQcHhENGz6v9jBZjkeZJBLMRZLlRWjcrWhKbEEHsjZJYiJP4u2n6n57Il9h9
OVqfK7RR3k1r9bMKzhYRnu1FsEPpMKKUrLPDChthxduXEPPZgoKGSYmhLAiYqyPg
USOyZzFt+wKBgQCmfjSgLSrZ2pSD0pWFciz8nqXZml+zr+cq/Jx8+kVw7cML7MdP
uOwVmPwPaAfN/Br6hFM7fKvsbSEQyOlgjA8XH7FFbFeJ/X2hjjY9Zvm8xGMO9cwy
/TM4tL9uo/W77r/jsPXXdRPARD98Z1xk3l1NMvaxZURtU/NN0On5iUABQQKBgGIu
FiER0R3iAF68WLAT7TVx4UgK2nsdO2eQCXkJDhpAyPEIjK8RWu/10oaS4k4guXYW
IYut3+dZpCFAVVCMwvaSlSMZbkk4464VBM3zxgRvxyoW1DXuO2ihWiD/fNZ8opTf
l7EcqR2fjOFKhgUF7qaZYG4GDYxHVuNhSkzDsdvHAoGBAIfDk7fLsG/BYROxJpzN
b1CoG8DE+DKYTWwMWW45rDF0ImbC6H3fg876CeZ3YKGWqt9qkha7gnGGVRRufP15
O7ZEXebZXeDYafXSNcnqSe7FSNtVr1eFlTWmL8OiWQuaqxjs/VogdWfhkEGPISVF
AOM3I6XSGx4NxW2RgYmvQZ4O
-----END PRIVATE KEY-----

Das System hat Ihre ursprüngliche Apache Virtualhost-Konfigurationsdatei automatisch geändert, um alle HTTP-Anforderungen an die HTTPS-Version umzuleiten.

Hier ist der Inhalt der aktualisierten ursprünglichen HTTP Virtualhost-Konfigurationsdatei mining-pool.conf:

<VirtualHost *:80>
ServerAdmin nobody@care.com
DocumentRoot /websites/www
ServerName mining-pool.ninja

<Directory /websites/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

ErrorLog /websites/logs/error.log
CustomLog /websites/logs/access.log combined
LogLevel error
RewriteEngine on
RewriteCond %{SERVER_NAME} =mining-pool.ninja
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost>

5. Testen Sie Ihre Apache HTTPS-Website

Um Ihre Installation zu testen, öffnen Sie Ihren Browser und geben Sie die HTTP-Adresse Ihrer Website ein.

In unserem Beispiel wurde die folgende URL in den Browser eingegeben:

• http://mining-pool.ninja

Anstelle der HTTP-Version sollte die HTTPS-Version Ihrer Website angezeigt werden.

Lets Encrypt Apache

Glückwunsch, Ihre Apache-Konfiguration verwendet jetzt das freie HTTPS-Zertifikat von LET'S ENCRYPT.

6. Erneuern Sie das Apache HTTPS-Zertifikat

Sie müssen wissen, dass die Zertifikate von Let's Encrypt nur neunzig Tage gültig sind.

Apache HTTPS Free Certificate

Das System erstellt eine geplante Aufgabe, um ein Zertifikat, dessen Gültigkeit innerhalb von dreißig Tagen abläuft, automatisch zu erneuern.

Der Name der geplanten Task ist certbot und befindet sich im Verzeichnis /etc/cron.d.

Hier ist der Inhalt der Datei /etc/cron.d/certbot:

# /etc/cron.d/certbot: crontab entries for the certbot package
#
# Upstream recommends attempting renewal twice a day
#
# Eventually, this will be an opportunity to validate certificates
# haven't been revoked, etc. Renewal will only occur if expiration
# is within 30 days.
#
# Important Note! This cronjob will NOT be executed if you are
# running systemd as your init system. If you are running systemd,
# the cronjob.timer function takes precedence over this cronjob. For
# more details, see the systemd.timer manpage, or use systemctl show
# certbot.timer.
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew

Verwenden Sie den folgenden Befehl, um den Prozess der Zertifikatserneuerung zu simulieren.

# certbot renew --dry-run

Wenn alles funktioniert, sollten Sie die folgenden Meldungen sehen:

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

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

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of apache server; fullchain is
/etc/letsencrypt/live/mining-pool.ninja/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/mining-pool.ninja/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.