IT-SERVICES

Опубликовано: 30 сентября 2018 г. 16:04

Получать ssl-сертификаты мы будем от Let’s Encrypt, кторые предоставляют их бесплатно. Срок действия 90 дней с возможностью продления

featured-image

Бесплатные SSL сертификаты для вашего сайта и редирект на https

Устанавливаем Certbot Client, который является инструментом для получения сертификатов от Let's Encrypt

 

[root@www ~]# yum --enablerepo=epel -y install certbot

Теперь можно пробовать:

[root@www ~]# certbot certonly --webroot -w /var/www/html -d test.domain.com

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Enter email address (used for urgent renewal and security notices)
# for only initial using, register your email address and agree to terms of use
# specify valid email address
(Enter 'c' to cancel): root@mail.test.domain.com
Starting new HTTPS connection (1): acme-v01.api.letsencrypt.org

-------------------------------------------------------------------------------

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-v01.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 EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: Y

Starting new HTTPS connection (1): supporters.eff.org
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for test.domain.com
Using the webroot path /var/www/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:

 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/test.domain.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/test.domain.com/privkey.pem
   Your cert will expire on 2018-05-22. 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

 

В конце должно быть Congratulations! Your certificate and chain have been….это значит, что все хорошо. У нас появились файлы в директории /etc/letsencrypt/live/test.domain.com/:

cert.pem ⇒ Сертификат сервера SSL (включает открытый ключ)

chain.pem ⇒ промежуточный сертификат

fullchain.pem ⇒ комбинированный файл cert.pem и chain.pem

privkey.pem ⇒ файл секретного ключа

Теперь добавляем ssl к нашему сайту.

Установим модуль mod_ssl к апачу:

[root@www ~]# yum -y install mod_ssl

Теперь редактируем файл конфига:

[root@www ~]# nano /etc/httpd/conf.d/ssl.conf

Ищем там эти строчки и меняем на свои(в моем примере будет облако nextcloud):

DocumentRoot "/var/www/nextcloud"

ServerName cloud.kurskmed.com:443

SSLProtocol all -SSLv2 -SSLv3

SSLCertificateFile /etc/letsencrypt/live/cloud.kurskmed.com/cert.pem

SSLCertificateKeyFile /etc/letsencrypt/live/cloud.kurskmed.com/privkey.pem

SSLCertificateChainFile /etc/letsencrypt/live/cloud.kurskmed.com/chain.pem

 

Перезапустим апач:

[root@www ~]# systemctl restart httpd

 

Теперь сделаем конфиг для виртуального хоста:

[root@www ~]# nano /etc/httpd/conf.d/vhost.conf

<VirtualHost *:80>
    DocumentRoot /var/www/nextcloud
    ServerName cloud.kurskmed.com
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>

 

[root@www ~]# systemctl restart httpd

 

Остается чтобы по умолчанию был https, а не http. Правим .htaccess

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]

Share on Facebook Share on LinkedIn Share on VK