GNU/Linux >> Linux Esercitazione >  >> Cent OS

Come configurare Let's Encrypt certificato SSL con Apache su CentOS 8 / RHEL 8 e CentOS 7 / RHEL 7

Let's Encrypt è un'autorità di certificazione ampiamente nota che fornisce certificati SSL gratuiti per i siti Web, lanciata nell'aprile 2016.

Con l'aiuto del client Certbot, la creazione, la convalida, la firma, l'implementazione e il rinnovo dei certificati sono completamente automatizzati.

Prerequisiti

Segui i collegamenti per avere lo stack LAMP o solo il server Web Apache installato sul tuo sistema.

LEGGI :Come installare lo stack LAMP su CentOS 8 / RHEL 8

LEGGI :Come installare lo stack LAMP su CentOS 7 / RHEL 7

Installa il client Certbot

Per generare e installare un certificato per qualsiasi dominio, è necessario disporre dell'accesso al terminale e del client Certbot ACME installato sul sistema. Il client Certbot automatizza l'emissione e l'installazione dei certificati senza tempi di inattività.

Il client Certbot è disponibile sul repository EPEL per CentOS 7/RHEL 7. Tuttavia, è necessario scaricare manualmente il client Certbot per CentOS 8/RHEL 8 dal suo sito ufficiale.

### CentOS 8 / RHEL 8 ###

yum install -y httpd mod_ssl

curl -O https://dl.eff.org/certbot-auto

mv certbot-auto /usr/local/bin/certbot-auto

chmod 0755 /usr/local/bin/certbot-auto

### CentOS 7 ###

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

yum install -y certbot python2-certbot-apache

### RHEL 7 ###

rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

subscription-manager repos --enable rhel-7-server-optional-rpms

yum install -y certbot python2-certbot-apache

Crea host virtuale

Creeremo un host virtuale per il dominio:www.itzgeek.net.

Questo host virtuale gestisce la versione HTTP del tuo dominio.
vi /etc/httpd/conf.d/www.itzgeek.net.conf

Usa le informazioni di seguito.

<VirtualHost *:80>
  ServerName itzgeek.net
  ServerAlias www.itzgeek.net
  DocumentRoot /var/www/www.itzgeek.net
  
  <Directory /var/www/www.itzgeek.net>
      Options -Indexes +FollowSymLinks
      AllowOverride All
  </Directory>

  ErrorLog /var/log/httpd/www.itzgeek.net-error.log
  CustomLog /var/log/httpd/www.itzgeek.net-access.log combined
</VirtualHost>

Crea una radice del documento per posizionare i tuoi file HTML.

mkdir -p /var/www/www.itzgeek.net

Inserisci il file HTML all'interno della radice del documento del tuo dominio.

echo "This is a test site @ www.itzgeek.net" > /var/www/www.itzgeek.net/index.html

Modifica l'autorizzazione della directory.

chown -R apache:apache /var/www/www.itzgeek.net

Riavvia il servizio Apache.

systemctl restart httpd

Crea / Aggiorna record DNS

Vai al tuo registrar di domini e crea un record A/CNAME per il tuo dominio. Es:www.itzgeek.net.

Attendi un po' di tempo per consentire la propagazione del record.

Controlla la propagazione DNS usando Nslookup yum install -y bind-utils.

Installa il certificato SSL Let's Encrypt

Usa il comando certbot per generare e installare il certificato Let's Encrypt.

### RHEL 8 ###

/usr/local/bin/certbot-auto --apache

### CentOS 7 / RHEL 7 ###

certbot --apache

Segui il prompt interattivo e installa il certificato.

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): [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 Sevice

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: itzgeek.net
2: 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): 2  << Choose the 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
Created an SSL vhost at /etc/httpd/conf.d/www.itzgeek.net-le-ssl.conf
Deploying Certificate to VirtualHost /etc/httpd/conf.d/www.itzgeek.net-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  << Redirect from HTTP to HTTPS
Redirecting vhost in /etc/httpd/conf.d/www.itzgeek.net.conf to ssl vhost in /etc/httpd/conf.d/www.itzgeek.net-le-ssl.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-10. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot-auto
   again with the "certonly" option. To non-interactively renew *all*
   of your certificates, run "certbot-auto 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

Firewall

Configura il firewall per consentire le richieste HTTPS.

firewall-cmd --permanent --add-port=443/tcp

firewall-cmd --reload

Verifica certificato Let's Encrypt

Verifica il certificato Let's Encrypt visitando la versione HTTPS del tuo sito web.

http://il-tuo-http-sito-web

O

https://tuo-https-sito-web

Ora dovresti ottenere una versione HTTPS del tuo sito.

Prova il certificato SSL Let's Encrypt

Verifica la presenza di problemi nel tuo certificato SSL e le relative valutazioni di sicurezza andando all'URL sottostante.

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

Rinnova il certificato Let's Encrypt

Il certificato Let's Encrypt è valido per 90 giorni dalla data di emissione e deve essere rinnovato prima della scadenza.

In CentOS 7 / RHEL 7, per impostazione predefinita, il client certbot crea una voce di pianificazione cron per rinnovare automaticamente i certificati Let's Encrypt.

Sfortunatamente, per CentOS 8 / RHEL 8, è necessario configurare manualmente lo scheduler cron.

echo "0 0,12 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && /usr/local/bin/certbot-auto renew" | sudo tee -a /etc/crontab > /dev/null

Puoi anche simulare il processo di rinnovo del certificato con il comando seguente per assicurarti che il rinnovo proceda senza intoppi.

### CentOS 8 / RHEL 8 ###

/usr/local/bin/certbot-auto renew --dry-run

### CentOS 7 / RHEL 7 ###

certbot renew --dry-run
Per rinnovare il certificato Let's Encrypt, esegui il comando precedente senza --dry-run opzione.

Risultato:

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 apache, Installer apache
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 apache 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.

Se l'output non segnala alcun problema, il rinnovo del certificato funzionerà come previsto.

Conclusione

È tutto. Spero che tu abbia imparato a configurare Let's Encrypt SSL Certificate con Apache su CentOS 8 / RHEL 8 e CentOS 7 / RHEL 7. Condividi il tuo feedback nella sezione commenti.


Cent OS
  1. Come installare il certificato SSL su Apache per CentOS 7

  2. Come installare SSL su RHEL 8 / CentOS 8

  3. Come installare mod_ssl su RHEL 8 / CentOS 8 con il server web httpd Apache

  4. Come installare Let's Encrypt con Apache su CentOS 7

  5. CentOS / RHEL:come abilitare SSL per Apache

Come configurare Let's Encrypt SSL con Apache su Fedora

Come installare Let's Encrypt (Certbot) su CentOS 8

Come installare Let's Encrypt SSL con Apache su CentOS 7

Come installare Let's Encrypt SSL con Lighttpd su CentOS 7

Come installare Let's Encrypt SSL su Ubuntu con Apache

Come proteggere Apache con Let's Encrypt SSL Certificate su CentOS 8