Инструкция для Apache и CentOS.
Для начала нужно установить certbot и дать ему определенные права. Выполните следующие команды:
wget https://dl.eff.org/certbot-auto sudo mv certbot-auto /usr/local/bin/certbot-auto sudo chown root /usr/local/bin/certbot-auto sudo chmod 0755 /usr/local/bin/certbot-auto
Далее вызываем certbot командой certbot и видим следующее:
certbot Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator apache, Installer apache Starting new HTTPS connection (1): acme-v02.api.letsencrypt.org Which names would you like to activate HTTPS for? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: site.com 2: site.ru - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate numbers separated by commas and/or spaces, or leave input blank to select all options shown (Enter 'c' to cancel):
Выбираем нужный сайт. Допустим, пишем 2 и Enter.
Если пишет такое:
You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry. (ref: /etc/letsencrypt/renewal/site.ru-0001.conf) What would you like to do? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: Attempt to reinstall this existing certificate 2: Renew & replace the cert (may be subject to CA rate limits) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Значит сертификат уже есть, и его можно обновить, как в пункте «Обновление сертификата».
Если сертификата нет, то должно быть следующее:
Obtaining a new certificate Performing the following challenges: http-01 challenge for site.ru Waiting for verification... Cleaning up challenges Created an SSL vhost at /etc/httpd/vhosts/site.ru-le-ssl.conf Deploying Certificate to VirtualHost /etc/httpd/vhosts/site.ru-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):
Здесь нас просят выбрать, нужно ли делать редирект с http на https. Если не нужно, то вводим 1. Если нужно, то вводим 2 и Enter:
Added an HTTP->HTTPS rewrite in addition to other RewriteRules; you may wish to check for overall consistency. Redirecting vhost in /etc/httpd/vhosts/site.ru.conf to ssl vhost in /etc/httpd/vhosts/site.ru-le-ssl.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://site.ru You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=site.ru - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/site.ru/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/site.ru/privkey.pem Your cert will expire on 2020-06-09. 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
Сертификат установлен, редирект с http на https поставлен.
Обновление сертификата
Чтобы обновить сертификат вручную вводим команду certbot renew:
certbot renew Saving debug log to /var/log/letsencrypt/letsencrypt.log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Processing /etc/letsencrypt/renewal/site.org.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Cert not yet due for renewal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Processing /etc/letsencrypt/renewal/site.ru.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Cert not yet due for renewal - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - The following certs are not due for renewal yet: /etc/letsencrypt/live/site.org/fullchain.pem expires on 2020-05-06 (skipped) /etc/letsencrypt/live/site.ru/fullchain.pem expires on 2020-05-04 (skipped) No renewals were attempted. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Мои сертификаты не нуждаются в обновлении.
Чтобы обновлять сертификат автоматически, редактируем crontab из-под рута:
crontab -e
И добавляем туда такую строку:
0 0,12 * * * certbot renew
Все. Сертификаты будут обновляться автоматически.