Instalando o Certificado Free HTTPS Apache no Ubuntu Linux

Este tutorial mostrará todas as etapas necessárias para instalar o Certificado Free HTTPS Apache no Ubuntu Linux.

Instalando o Apache no Ubuntu Linux

Vamos instalar o Apache com suporte adequado ao PHP.

Use o comando APT do Ubuntu para instalar o servidor Apache.

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

Opcional. Use o seguinte comando para instalar os módulos PHP mais usados do 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

Ative o mod_ssl do Apache.

Ative o mod_rewrite do Apache.

Edite o arquivo apache2.conf.

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

Adicione as seguintes linhas no final do apache2.conf

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

Reinicie o serviço Apache.

# service apache2 restart

Você terminou a instalação do servidor da Web Apache no Ubuntu Linux.

Configurando Hosts Virtuais do Apache

Hosts virtuais se um recurso permitir que um servidor Apache ofereça vários sites usando o mesmo endereço IP.

Vamos criar a infraestrutura necessária para usar o recurso Apache VirtualHosts.

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

Nosso site será chamado mining-pool.ninja.

Os arquivos do site mining-pool.ninja devem estar dentro do diretório / websites / mining-pool / www.

Os logs de mining-pool.ninja serão armazenados dentro do diretório / sites / mining-pool / logs.

Alert!

Mining-pool.ninja was used as an example!

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

Crie um arquivo de configuração do Apache Virtualhost em seu site.

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

Aqui está o arquivo com nossa configuração.

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

Ative o arquivo de configuração do Virtualhost do seu site.

Reinicie o serviço Apache.

# a2ensite mining-pool.conf
# service apache2 restart

Você terminou a configuração do Apache VirtualHosts.

Configurando o Registro de Domínio DNS

Acesse o GODADDY e compre um domínio DNS.

Em nosso exemplo, compramos o domínio chamado MINING-POOL.NINJA.

Você pode usar qualquer site para comprar um domínio DNS, o GoDaddy é apenas minha escolha pessoal.

Crie uma entrada de DNS apontando seu site para o computador que está executando o Apache.

Em nosso exemplo, criamos uma entrada de DNS apontando o domínio MINING-POOL.NINJA para o endereço IP 35.163.100.49.

Godaddy Apache DNS Configuration

Use o comando NSLOOKUP para testar sua configuração 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

Você terminou a configuração do domínio DNS.

Abra seu navegador e tente acessar a versão HTTP do seu site.

Em nosso exemplo, o seguinte URL foi inserido no navegador:

• http://mining-pool.ninja

Apache Virtualhost HTTP

Agora, nossa única preocupação é instalar o certificado Free HTTPS e redirecionar todo o tráfego HTTP para a versão HTTPS do nosso site automaticamente.

Configurando o Certificado Free HTTPS no Apache

Instale os pacotes necessários para usar os Certificados LET'S ENCRYPT Free SSL / TLS no 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 o certificado Free HTTPS do Apache.

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

• Pressione (A) para concordar com os Termos de Serviço.
• Pressione (Y) para compartilhar seu e-mail e receber Newsletters.
• Pressione (2) para redirecionar automaticamente seu site HTTP para as versões 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

O sistema solicitará automaticamente o certificado gratuito.

Ele também irá configurar seu servidor web Apache para redirecionar todo o acesso HTTP para a versão HTTPS do seu site.

Em nosso exemplo, o sistema criou um arquivo de configuração HTTPS Virtualhost chamado mining-pool-le-ssl.conf

Aqui está o conteúdo do arquivo de configuração 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>

O arquivo KEY contém sua chave privada do Certificado e deve ser mantido em um local seguro o tempo todo.

O arquivo de chave para mining-pool.ninja foi armazenado em /etc/letsencrypt/live/mining-pool.ninja/privkey.pem.

O sistema modifica automaticamente o arquivo de configuração original do Apache Virtualhost.

Ele redirecionará automaticamente todas as solicitações HTTP para a versão HTTPS do seu site.

Aqui está o conteúdo do arquivo de configuração do HTTP Virtualhost original atualizado, 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>

Testando o Certificado Free HTTPS no Apache

Toda a configuração necessária está concluída.

Está na hora de testar sua configuração.

Abra seu navegador e tente acessar a versão HTTP do seu site.

Em nosso exemplo, o seguinte URL foi inserido no navegador:

• http://mining-pool.ninja

O Apache redirecionará automaticamente a solicitação HTTP para a versão HTTPS do seu site.

Lets Encrypt Apache HTTPS

Você concluiu a configuração do certificado livre do Apache HTTPS.

Como Renovar o Certificado Free HTTPS

Os Certificados LET'S ENCRYPT Free SSL / TLS são válidos apenas por 90 dias.

O sistema cria uma tarefa agendada para renovar automaticamente qualquer certificado dentro de trinta dias após a expiração.

O nome da tarefa agendada é certbot e está localizado dentro do diretório /etc/cron.d.

Aqui está o conteúdo do arquivo /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

Use o seguinte comando para simular o processo de renovação do certificado.

# certbot renew --dry-run

Você deve ver as seguintes mensagens:

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.