Android

I-secure ang apache sa pag-encrypt natin sa mga sentimo 8

Настройка SSL/TLS для Apache в CentOS 8

Настройка SSL/TLS для Apache в CentOS 8

Talaan ng mga Nilalaman:

Anonim

Hayaan ang Encrypt ay isang libre, awtomatiko, at bukas na awtoridad ng sertipiko na binuo ng Internet Security Research Group (ISRG) na nagbibigay ng mga libreng sertipiko ng SSL.

Ang mga sertipiko na inisyu ng Let Encrypt ay pinagkakatiwalaan ng lahat ng mga pangunahing browser at wasto para sa 90 araw mula sa petsa ng isyu.

Ipinapaliwanag ng tutorial na ito kung paano mag-install ng isang libreng Let’s Encrypt SSL certificate sa CentOS 8 na tumatakbo sa Apache bilang isang web server. Gagamitin namin ang tool na sertbot upang makakuha at mai-renew ang mga sertipiko.

Mga kinakailangan

Tiyakin na ang mga sumusunod na kinakailangan ay natutugunan bago magpatuloy:

  • Magkaroon ng isang domain name na tumuturo sa iyong public server IP. Gagamitin namin ang example.com .Apache ay naka-install at tumatakbo sa iyong server gamit ang isang virtual host na na-configure para sa iyong domain.Ports 80 at 443 ay nakabukas sa iyong firewall.

I-install ang sumusunod na mga pakete na kinakailangan para sa isang SSL na naka-encrypt na web server:

sudo dnf install mod_ssl openssl

Kapag naka-install ang pakete ng mod_ssl, dapat itong lumikha ng isang naka-sign na key at mga file ng sertipiko para sa localhost. Kung ang mga file ay hindi awtomatikong nilikha, maaari mong likhain ang mga ito gamit ang openssl command:

sudo openssl req -newkey rsa:4096 -x509 -sha256 -days 3650 -nodes \ -out /etc/pki/tls/certs/localhost.crt \ -keyout /etc/pki/tls/private/localhost.key -out /etc/pki/tls/certs/localhost.crt \ -keyout /etc/pki/tls/private/localhost.key -out /etc/pki/tls/certs/localhost.crt \ -keyout /etc/pki/tls/private/localhost.key -out /etc/pki/tls/certs/localhost.crt \ -keyout /etc/pki/tls/private/localhost.key -out /etc/pki/tls/certs/localhost.crt \ -keyout /etc/pki/tls/private/localhost.key

I-install ang Certbot

Ang Certbot ay isang libreng tool na linya ng command-line na nagpapagaan sa proseso para sa pagkuha at pag-update ng I-encrypt Natin ang mga sertipiko ng SSL at paganahin ng auto-HTTPS sa iyong server.

Ang sertipikong pakete ay hindi kasama sa karaniwang mga repositori ng CentOS 8, ngunit maaari itong mai-download mula sa website ng nagbebenta.

Patakbuhin ang sumusunod na utos ng wget bilang root o sudo na gumagamit upang i-download ang script ng sertbot sa /usr/local/bin direktoryo:

sudo wget -P /usr/local/bin

Kapag kumpleto ang pag-download, gawin ang file maipapatupad:

sudo chmod +x /usr/local/bin/certbot-auto

Bumuo ng Malakas na Dh (Diffie-Hellman) Grupo

Ang diffie-Hellman key exchange (DH) ay isang paraan ng ligtas na pagpapalitan ng mga key ng cryptographic sa isang hindi ligtas na channel ng komunikasyon. Bumuo ng isang bagong hanay ng mga 2048 bit na mga parameter ng DH upang palakasin ang seguridad:

sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

Maaari mong baguhin ang laki ng hanggang sa 4096 bit, ngunit ang henerasyon ay maaaring tumagal ng higit sa 30 minuto depende sa entropy ng system.

Pagkuha ng isang I-encrypt na SSL sertipiko

Upang makakuha ng isang SSL certificate para sa domain ay gagamitin namin ang plugin ng Webroot na gumagana sa pamamagitan ng paglikha ng isang pansamantalang file para sa pagpapatunay ng hiniling na domain sa ${webroot-path}/.well-known/acme-challenge . Ginagawa ng server ng Let's Encrypt ang mga kahilingan ng HTTP sa pansamantalang file upang mapatunayan na ang hiniling na domain ay nagpasiya sa server kung saan tumatakbo ang sertbot.

Upang gawing mas simple ang pag-setup ay i-map namin ang lahat ng mga kahilingan sa HTTP para sa .well-known/acme-challenge sa isang solong direktoryo, /var/lib/letsencrypt .

Patakbuhin ang sumusunod na mga utos upang lumikha ng direktoryo at gawin itong nakasulat para sa Apache server.

sudo mkdir -p /var/lib/letsencrypt/.well-known sudo chgrp apache /var/lib/letsencrypt sudo chmod g+s /var/lib/letsencrypt

Upang maiwasan ang pagdoble ng code at gawing mas maaasahan ang pagsasaayos, lumikha ng sumusunod na dalawang snippet ng pagsasaayos:

/etc/httpd/conf.d/letsencrypt.conf

Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS Alias /.well-known/acme-challenge/ "/var/lib/letsencrypt/.well-known/acme-challenge/" AllowOverride None Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS /etc/httpd/conf.d/ssl-params.conf

SSLCipherSuite EECDH+AESGCM:EDH+AESGCM # Requires Apache 2.4.36 & OpenSSL 1.1.1 SSLProtocol -all +TLSv1.3 +TLSv1.2 SSLOpenSSLConfCmd Curves X25519:secp521r1:secp384r1:prime256v1 # Older versions # SSLProtocol All -SSLv2 -SSLv3 -TLSv1 -TLSv1.1 SSLHonorCipherOrder On Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" Header always set X-Frame-Options DENY Header always set X-Content-Type-Options nosniff # Requires Apache >= 2.4 SSLCompression off SSLUseStapling on SSLStaplingCache "shmcb:logs/stapling-cache(150000)" # Requires Apache >= 2.4.11 SSLSessionTickets Off SSLOpenSSLConfCmd DHParameters "/etc/ssl/certs/dhparam.pem"

Ang snippet sa itaas ay ang paggamit ng mga tsinelas na inirerekomenda ni Cipherli.st. Pinapayagan nito ang OCSP Stapling, HTTP Strict Transport Security (HSTS), Dh key, at nagpapatupad ng kaunting seguridad ‑ na nakatuon ang mga header ng

Reload ang pagsasaayos ng Apache para sa mga pagbabago na magkakabisa:

sudo systemctl reload

Ngayon, maaari mong patakbuhin ang script ng script na may webroot plugin at makuha ang mga file ng sertipiko ng SSL:

sudo /usr/local/bin/certbot-auto certonly --agree-tos --email [email protected] --webroot -w /var/lib/letsencrypt/ -d example.com -d www.example.com

Sa tagumpay, i-print ng sertbot ang sumusunod na mensahe:

IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2020-01-26. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto 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:

Ngayon na ang lahat ay naka-set up, i-edit ang iyong virtual virtual na pagsasaayos ng host tulad ng mga sumusunod:

/etc/httpd/conf.d/example.com.conf

ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem # Other Apache Configuration ServerName example.com ServerAlias www.example.com Redirect permanent / https://example.com/ ServerName example.com ServerAlias www.example.com Protocols h2 http:/1.1 Redirect permanent / https://example.com/ DocumentRoot /var/www/example.com/public_html ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined SSLEngine On SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem # Other Apache Configuration

Ang pagsasaayos sa itaas ay pagpilit sa HTTPS at pag-redirect mula sa www hanggang sa di-www na bersyon. Pinapayagan din nito ang HTTP / 2, na gagawing mas mabilis at mas matatag ang iyong mga site. Mag-file ng malaya upang maiayos ang pagsasaayos ayon sa iyong mga pangangailangan.

I-restart ang serbisyo ng Apache:

sudo systemctl restart

Maaari mo na ngayong buksan ang iyong website gamit ang https:// , at mapapansin mo ang isang berdeng icon ng lock.

Pag-update ng Auto I-encrypt ang SSL certificate

Ang mga sertipiko ng Encrypt ay may bisa sa loob ng 90 araw. Upang awtomatikong i-renew ang mga sertipiko bago mag-expire, gagawa kami ng isang cronjob na tatakbo nang dalawang beses sa isang araw at awtomatikong i-renew ang anumang sertipiko 30 araw bago ito mag-expire.

Patakbuhin ang sumusunod na utos upang lumikha ng isang bagong cronjob na magpapabago ng sertipiko at i-restart ang Apache:

echo "0 0, 12 * * * root python3 -c 'import random; import time; time.sleep(random.random() * 3600)' && /usr/local/bin/certbot-auto -q renew --renew-hook \"systemctl reload httpd\"" | sudo tee -a /etc/crontab > /dev/null

Upang masubukan ang proseso ng pag-renew, gamitin ang utos ng sertbot na sinusundan ng --dry-run :

sudo /usr/local/bin/certbot-auto renew --dry-run

Kung walang mga pagkakamali, nangangahulugan ito na matagumpay ang proseso ng pag-update.

Konklusyon

Sa tutorial na ito, napag-usapan namin ang tungkol sa kung paano gamitin ang client ng Let Encrypt na kliyente sa CentOS upang makakuha ng mga sertipiko ng SSL para sa iyong mga domain. Ipinakita mo rin sa iyo kung paano i-configure ang Apache upang magamit ang mga sertipiko at mag-set up ng isang cronjob para sa pag-renew ng awtomatiko.

Upang malaman ang higit pa tungkol sa script ng Certbot, bisitahin ang dokumentasyon ng Certbot.

apache sentimo hayaan encrypt ang sertbot ssl