Instalación de Apache Free HTTPS Certificate en Ubuntu Linux

Este tutorial le mostrará todos los pasos necesarios para instalar Apache Free HTTPS Certificate en Ubuntu Linux.

Instalación de Apache en Ubuntu Linux

Instalemos Apache con el soporte adecuado de PHP.

Use el comando Ubuntu APT para instalar el servidor Apache.

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

Opcional. Use el siguiente comando para instalar los módulos PHP más utilizados de 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

Habilitar Apache mod_ssl.

Habilitar apache mod_rewrite.

Edite el archivo apache2.conf.

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

Agregue las siguientes líneas al final de apache2.conf

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

Reinicie el servicio de Apache.

# service apache2 restart

Terminaste la instalación del servidor web Apache en Ubuntu Linux.

Configurando los Hosts Virtuales de Apache

Los hosts virtuales son una característica que permite que un servidor Apache ofrezca múltiples sitios web con la misma dirección IP.

Vamos a crear la infraestructura necesaria para usar la función Apache VirtualHosts.

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

Nuestro sitio web se llamará mining-pool.ninja.

Los archivos del sitio web mining-pool.ninja deben estar dentro del directorio / websites / mining-pool / www.

Los registros mining-pool.ninja se almacenarán dentro del directorio / 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.

Cree un archivo de configuración de Apache Virtualhost para su sitio web.

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

Aquí está el archivo con nuestra configuración.

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

Habilite el archivo de configuración de su sitio web Virtualhost.

Reinicie el servicio de Apache.

# a2ensite mining-pool.conf
# service apache2 restart

Terminaste la configuración de Apache VirtualHosts.

Configurando el Registro de Dominios DNS

Acceder al GODADDY y comprar un dominio DNS.

En nuestro ejemplo, compramos el dominio llamado MINING-POOL.NINJA.

Puedes usar cualquier sitio web para comprar un dominio DNS, GoDaddy es solo mi elección personal.

Cree una entrada de DNS que apunte su sitio web a la computadora que ejecuta Apache.

En nuestro ejemplo, creamos una entrada de DNS que apunta el dominio MINING-POOL.NINJA a la dirección IP 35.163.100.49.

Godaddy Apache DNS Configuration

Utilice el comando NSLOOKUP para probar su configuración de DNS

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

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

Has terminado la configuración del dominio DNS.

Abra su navegador e intente acceder a la versión HTTP de su sitio web.

En nuestro ejemplo, la siguiente URL se ingresó en el navegador:

• http://mining-pool.ninja

Apache Virtualhost HTTP

Ahora, nuestra única preocupación es instalar el certificado HTTPS gratuito y redirigir todo el tráfico HTTP a la versión HTTPS de nuestro sitio web automáticamente.

Configurando el Certificado Free HTTPS en Apache

Instale los paquetes necesarios para usar los certificados SSL / TLS gratuitos de LET ENCRYPT en 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

Solicite e instale el certificado Free HTTPS de Apache.

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

• Presione (A) para aceptar los Términos de servicio.
• Presione (Y) para compartir su correo electrónico y recibir boletines.
• Presione (2) para redireccionar automáticamente su sitio web HTTP a las versiones 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

El sistema solicitará automáticamente el certificado gratuito.

También configurará su servidor web Apache para redirigir todo el acceso HTTP a la versión HTTPS de su sitio web.

En nuestro ejemplo, el sistema creó un archivo de configuración de host virtual de HTTPS llamado mining-pool-le-ssl.conf

Aquí está el contenido del archivo de configuración de 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>

El archivo KEY contiene su clave privada de certificado y debe guardarse en un lugar seguro todo el tiempo.

El archivo de claves para mining-pool.ninja se almacenó en /etc/letsencrypt/live/mining-pool.ninja/privkey.pem.

El sistema modifica automáticamente el archivo de configuración original de Apache Virtualhost.

Redirigirá automáticamente todas las solicitudes HTTP a la versión HTTPS de su sitio web.

Aquí está el contenido del archivo de configuración de HTTP Virtualhost original actualizado, 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>

Probando el Certificado Free HTTPS en Apache

Se realiza toda la configuración requerida.

Es hora de probar su configuración.

Abra su navegador e intente acceder a la versión HTTP de su sitio web.

En nuestro ejemplo, la siguiente URL se ingresó en el navegador:

• http://mining-pool.ninja

Apache redirigirá automáticamente la solicitud HTTP a la versión HTTPS de su sitio web.

Lets Encrypt Apache HTTPS

Usted terminó la configuración del certificado gratuito Apache HTTPS.

Cómo Renovar el Certificado Free HTTPS

Los certificados gratuitos SSL / TLS de LET'S ENCRYPT son válidos solo por 90 días.

El sistema crea una tarea programada para renovar automáticamente cualquier certificado dentro de los treinta días de vencimiento.

El nombre de la tarea programada es certbot y se encuentra dentro del directorio /etc/cron.d.

Aquí está el contenido del archivo /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

Utilice el siguiente comando para simular el proceso de renovación de certificado.

# certbot renew --dry-run

Deberías ver los siguientes mensajes:

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.