Installazione del Certificato HTTPS Apache Free su Ubuntu Linux

Questo tutorial ti mostrerà tutti i passaggi necessari per installare il certificato HTTPS Apache Free su Ubuntu Linux.

Installare Apache su Ubuntu Linux

Installiamo Apache con il corretto supporto PHP.

Utilizzare il comando APT di Ubuntu per installare il server Apache.

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

Opzionale. Utilizzare il seguente comando per installare i moduli PHP più usati di Apache.

# apt-get install php7.2-xml php7.2-curl php7.2-gd php7.2-mbstring
# apt-get install php7.2-bz2 php7.2-zip php7.2-json php7.2-readline

Abilita Apache mod_ssl.

Abilita mod_rewrite di Apache.

Modifica il file apache2.conf.

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

Aggiungi le seguenti righe alla fine di apache2.conf

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

Riavvia il servizio Apache.

# service apache2 restart

Hai terminato l'installazione del server Web Apache su Ubuntu Linux.

Configurazione Degli Host Virtuali di Apache

Host virtuali se una funzionalità che consente a un server Apache di offrire più siti Web utilizzando lo stesso indirizzo IP.

Consente di creare l'infrastruttura necessaria per utilizzare la funzionalità Apache VirtualHosts.

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

Il nostro sito Web sarà denominato mining-pool.ninja.

I file del sito Web mining-pool.ninja devono trovarsi all'interno della directory / websites / mining-pool / www.

I log di mining-pool.ninja verranno memorizzati nella directory / websites / mining-pool / logs.

Alert!

Mining-pool.ninja was used as an example!

You need to change your configuration files to reflect your website name.

Crea un file di configurazione di Apache Virtualhost sul tuo sito web.

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

Ecco il file con la nostra configurazione.

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

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

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

Abilita il tuo file di configurazione di Virtualhost del sito.

Riavvia il servizio Apache.

# a2ensite mining-pool.conf
# service apache2 restart

Hai terminato la configurazione di Apache VirtualHosts.

Configurazione del Registro del Dominio DNS

Accedi a GODADDY e acquistare un dominio DNS.

Nel nostro esempio, acquistiamo il dominio denominato MINING-POOL.NINJA.

Puoi utilizzare qualsiasi sito web per acquistare un dominio DNS, GoDaddy è solo una mia scelta personale.

Creare una voce DNS che indirizza il sito Web al computer che esegue Apache.

Nel nostro esempio, abbiamo creato una voce DNS che indirizza il dominio MINING-POOL.NINJA all'indirizzo IP 35.163.100.49.

Godaddy Apache DNS Configuration

Utilizzare il comando NSLOOKUP per verificare la configurazione DNS

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

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

Hai finito la configurazione del dominio DNS.

Apri il browser e prova ad accedere alla versione HTTP del tuo sito web.

Nel nostro esempio, il seguente URL è stato inserito nel browser:

• http://mining-pool.ninja

Apache Virtualhost HTTP

Ora, la nostra unica preoccupazione è installare il certificato HTTPS gratuito e reindirizzare automaticamente tutto il traffico HTTP alla versione HTTPS del nostro sito web.

Configurazione del Certificato HTTPS Gratuito su Apache

Installa i pacchetti richiesti per utilizzare i certificati SSL / TLS gratuiti di LET'S ENCRYPT su Ubuntu Linux

# 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

Richiedi e installa il certificato HTTPS gratuito Apache.

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

• Premere (A) per accettare i Termini di servizio.
• Premere (Y) per condividere l'e-mail e ricevere le newsletter.
• Premere (2) per reindirizzare automaticamente il sito Web HTTP alle versioni HTTPS.

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

Il sistema richiederà automaticamente il certificato gratuito.

Configura anche il tuo server Web Apache per reindirizzare tutto l'accesso HTTP alla versione HTTPS del tuo sito web.

Nel nostro esempio, il sistema ha creato un file di configurazione di HTTPS Virtualhost denominato mining-pool-le-ssl.conf

Ecco il contenuto del file di configurazione di HTTPS Virtualhost 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>

Il file KEY contiene la chiave privata del certificato e deve essere conservato in un luogo sicuro per tutto il tempo.

Il file chiave di mining-pool.ninja è stato memorizzato in /etc/letsencrypt/live/mining-pool.ninja/privkey.pem.

Il sistema modifica automaticamente il file di configurazione originale di Apache Virtualhost.

Reindirizzerà automaticamente tutte le richieste HTTP alla versione HTTPS del tuo sito web.

Ecco il contenuto del file di configurazione HTTP Virtualhost originale aggiornato, 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>

Test del Certificato HTTPS Gratuito su Apache

Tutta la configurazione richiesta è fatta

È tempo di testare la tua configurazione.

Apri il browser e prova ad accedere alla versione HTTP del tuo sito web.

Nel nostro esempio, il seguente URL è stato inserito nel browser:

• http://mining-pool.ninja

Apache reindirizzerà automaticamente la richiesta HTTP alla versione HTTPS del tuo sito web.

Lets Encrypt Apache HTTPS

Hai terminato la configurazione gratuita del certificato HTTPS di Apache.

Come Rinnovare il Certificato HTTPS Gratuito

I certificati SSL / TLS gratuiti di LET'S ENCRYPT sono validi solo per 90 giorni.

Il sistema crea un'attività programmata per rinnovare automaticamente qualsiasi certificato entro trenta giorni dalla scadenza.

Il nome dell'attività pianificata è certbot e si trova all'interno della directory /etc/cron.d.

Ecco il contenuto del file /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

Utilizzare il seguente comando per simulare il processo di rinnovo del certificato.

# certbot renew --dry-run

Dovresti vedere i seguenti messaggi:

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.