Установка certbot
Добавьте PPA certbot:
sudo apt-get update sudo apt-get install software-properties-common sudo add-apt-repository universe sudo add-apt-repository ppa:certbot/certbot sudo apt-get update
Установите certbot:
sudo apt-get update sudo apt-get install certbot -t stretch-backports
Создание сертификата
Останавливаем Apache:
sudo service apache2 stop
Останавливать Apache на время создания/продления сертификата нужно потому, что мы запускаем certbot в режиме standalone. В этом режиме он, для подтверждения владения доменом, сам начинает работать как веб-сервер (начинает слушать на порту 80), и Apache нужно остановить, чтобы они не конфликтовали.
Запускаем certbot (вместо "YOUR_DOMAIN" нужно ввести ваш домен):
sudo certbot certonly --standalone -d YOUR_DOMAIN
Вас спросят email:
Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator standalone, Installer None Enter email address (used for urgent renewal and security notices) (Enter 'c' to cancel):
Попросят принять Terms of Service:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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:
Попросят поделиться email'ом с EFF (здесь можно отказаться):
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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:
Пошёл процесс получения сертификата:
Obtaining a new certificate Performing the following challenges: http-01 challenge for YOUR_DOMAIN Waiting for verification... Cleaning up challenges
Успех:
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/YOUR_DOMAIN/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/YOUR_DOMAIN/privkey.pem Your cert will expire on 2020-07-12. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot 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
Теперь нужно заменить самоподписанный сертификат на новый от Let's Encrypt.
Заменяем в файле /etc/apache2/sites-enabled/abills_httpd.conf строки
SSLCertificateFile /usr/abills/Certs/server.crt SSLCertificateKeyFile /usr/abills/Certs/server.key
на
SSLCertificateFile /etc/letsencrypt/live/YOUR_DOMAIN/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/YOUR_DOMAIN/privkey.pem
где YOUR_DOMAIN - ваш домен.
Запускаем Apache:
sudo service apache2 start
Теперь можно зайти на сайт с браузера, и проверить, что браузер считает этот сертификат валидным.
Настройка автопродления сертификата
certbot сам настроил автопродление на предыдущем шаге (прописав себя в cron или в systemd timers). Проверяем:
$ systemctl list-timers --all NEXT LEFT LAST PASSED UNIT ACTIVATES ... Fri 2021-03-19 23:18:22 EET 11h left n/a n/a certbot.timer certbot.service ...
Нужно только настроить хуки, чтобы перед запуском продления apache останавливался, а после - запускался:
sudo sh -c 'printf "#!/bin/sh\nservice apache2 stop\n" > /etc/letsencrypt/renewal-hooks/pre/apache.sh' sudo sh -c 'printf "#!/bin/sh\nservice apache2 start\n" > /etc/letsencrypt/renewal-hooks/post/apache.sh' sudo chmod 755 /etc/letsencrypt/renewal-hooks/pre/apache.sh sudo chmod 755 /etc/letsencrypt/renewal-hooks/post/apache.sh