ວິທີການຮັບປະກັນ Apache ດ້ວຍ SSL ແລະ Let’s Encrypt ໃນ FreeBSD


ໃນບົດແນະ ນຳ ນີ້ພວກເຮົາຈະຮຽນຮູ້ວິທີການຮັບປະກັນເຊີຟເວີ Apache HTTP ດ້ວຍໃບຢັ້ງຢືນ TLS/SSL ທີ່ສະ ເໜີ ໂດຍ Let’s Encrypt ໃນ FreeBSD 11.x. ພວກເຮົາຍັງຈະໄດ້ກ່າວເຖິງວິທີການອັດຕະໂນມັດຂັ້ນຕອນການຕໍ່ອາຍຸໃບຢັ້ງຢືນ ສຳ ລັບການເຂົ້າລະຫັດຂອງ Lets '.

ໃບຢັ້ງຢືນ TLS/SSL ຖືກໃຊ້ໂດຍເຄື່ອງແມ່ຂ່າຍເວັບໄຊຕ໌ Apache ເພື່ອເຂົ້າລະຫັດການສື່ສານລະຫວ່າງຂໍ້ສຸດທ້າຍ, ຫຼື ທຳ ມະດາລະຫວ່າງເຊີຟເວີແລະລູກຄ້າເພື່ອໃຫ້ມີຄວາມປອດໄພ. Let’s Encrypt ໃຫ້ບໍລິການເສັ້ນໃຊ້ ຄຳ ສັ່ງ certbot ເຊິ່ງເປັນໂປແກຼມທີ່ສາມາດ ອຳ ນວຍຄວາມສະດວກໃຫ້ທ່ານສາມາດໄດ້ຮັບໃບຢັ້ງຢືນທີ່ເຊື່ອຖືໄດ້ໂດຍບໍ່ເສຍຄ່າ.

<

  • ຕິດຕັ້ງ FreeBSD 11.x
  • 10 ສິ່ງທີ່ຕ້ອງເຮັດຫຼັງຈາກຕິດຕັ້ງ FreeBSD ແລ້ວ
  • ວິທີການຕິດຕັ້ງ Apache, MariaDB ແລະ PHP ໃນ FreeBSD
  • ຂັ້ນຕອນທີ 1: ຕັ້ງຄ່າ Apache SSL ໃນ FreeBSD

    1. ກ່ອນທີ່ຈະເລີ່ມຕົ້ນຕິດຕັ້ງຜົນປະໂຫຍດ certbot ແລະສ້າງເອກະສານການຕັ້ງຄ່າ TSL ສຳ ລັບ Apache, ທຳ ອິດສ້າງສອງລາຍຊື່ທີ່ແຕກຕ່າງກັນທີ່ມີຊື່ວ່າ sites-available ແລະ sites-enable ໃນລະບົບການຕັ້ງຄ່າຮາກຂອງ Apache ໂດຍອອກ ຄຳ ສັ່ງຂ້າງລຸ່ມນີ້.

    ຈຸດປະສົງຂອງສອງລາຍການນີ້ແມ່ນເພື່ອ ອຳ ນວຍຄວາມສະດວກໃຫ້ແກ່ການຄຸ້ມຄອງການຕັ້ງຄ່າໂຮດຕິ້ງເສມືນໃນລະບົບ, ໂດຍບໍ່ຕ້ອງດັດແປງເອກະສານການຕັ້ງຄ່າ Apache httpd.conf ຕົ້ນຕໍໃນແຕ່ລະຄັ້ງທີ່ພວກເຮົາເພີ່ມໂຮດ ໃໝ່.

    # mkdir /usr/local/etc/apache24/sites-available
    # mkdir /usr/local/etc/apache24/sites-enabled
    

    2. ຫຼັງຈາກທີ່ທ່ານໄດ້ສ້າງໄດເລກະທໍລີທັງສອງ, ເປີດເອກະສານ Apache httpd.conf ກັບບັນນາທິການຕົວ ໜັງ ສືແລະເພີ່ມແຖວຕໍ່ໄປນີ້ໃສ່ບ່ອນສຸດທ້າຍຂອງເອກະສານດັ່ງຮູບຂ້າງລຸ່ມນີ້.

    # nano /usr/local/etc/apache24/httpd.conf
    

    ຕື່ມແຖວຕໍ່ໄປນີ້:

    IncludeOptional etc/apache24/sites-enabled/*.conf
    

    3. ຕໍ່ໄປ, ເປີດໃຊ້ໂມດູນ TLS ສຳ ລັບ Apache ໂດຍການສ້າງເອກະສານ ໃໝ່ ຕໍ່ໄປນີ້ທີ່ມີຊື່ວ່າ 020_mod_ssl.conf ໃນໂມດູນ modules.d ທີ່ມີເນື້ອຫາຕໍ່ໄປນີ້.

    # nano /usr/local/etc/apache24/modules.d/020_mod_ssl.conf
    

    ຕື່ມສາຍຕໍ່ໄປນີ້ໃສ່ແຟ້ມ 020_mod_ssl.conf.

    Listen 443
    SSLProtocol ALL -SSLv2 -SSLv3
    SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
    SSLPassPhraseDialog  builtin
    SSLSessionCacheTimeout  300
    

    4. ດຽວນີ້, ຍົກເລີກເອກະສານ SSL ຈາກ /usr/local/etc/apache24/httpd.conf ໂດຍການ ກຳ ຈັດ hashtag ຕັ້ງແຕ່ເລີ່ມຕົ້ນຂອງແຖວຕໍ່ໄປນີ້ດັ່ງຮູບຂ້າງລຸ່ມນີ້:

    LoadModule ssl_module libexec/apache24/mod_ssl.so
    

    5. ຕໍ່ໄປ, ສ້າງເອກະສານການຕັ້ງຄ່າ TLS ສຳ ລັບໂດເມນຂອງທ່ານຢູ່ໃນເວັບໄຊທ໌ທີ່ມີຢູ່ໃນເວັບໄຊທ໌, ທີ່ ເໝາະ ສົມກັບຊື່ຂອງໂດເມນຂອງທ່ານ, ດັ່ງທີ່ຖືກ ນຳ ສະ ເໜີ ໃນບົດຄັດຫຍໍ້ລຸ່ມນີ້:

    # nano /usr/local/etc/apache24/sites-available/bsd.lan-ssl.conf
    

    ເພີ່ມການຕັ້ງຄ່າ virtualhost ຕໍ່ໄປນີ້ເພື່ອຍື່ນ bsd.lan-ssl.conf.

    <VirtualHost *:443>
        ServerName www.yourdomain.com
    	ServerAlias yourdomain.com
                    DocumentRoot "/usr/local/www/apache24/data/"
    	SSLEngine on
    
    	SSLCertificateFile "/usr/local/etc/letsencrypt/live/www.yourdomain.com/cert.pem"
    	SSLCertificateKeyFile "/usr/local/etc/letsencrypt/live/www.yourdomain.com/privkey.pem"
    	SSLCertificateChainFile "/usr/local/etc/letsencrypt/live/www.yourdomain.com/fullchain.pem"
    
    <FilesMatch "\.(cgi|shtml|phtml|php)$">
        SSLOptions +StdEnvVars
    </FilesMatch>
    
    <Directory "/usr/local/www/apache24/cgi-bin">
        SSLOptions +StdEnvVars
    </Directory>
    
    	BrowserMatch "MSIE [2-5]" \
            nokeepalive ssl-unclean-shutdown \
            downgrade-1.0 force-response-1.0
    
    	CustomLog "/var/log/apache/httpd-ssl_request.log" \
              "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
    
    	<Directory "/usr/local/www/apache24/data/">
                Options Indexes FollowSymLinks MultiViews
            #AllowOverride controls what directives may be placed in .htaccess files.       
                            AllowOverride All
            #Controls who can get stuff from this server file
                            Require all granted
            </Directory>
           
        ErrorLog "/var/log/apache/yourdomain.ssl-error.log"
        CustomLog "/var/log/apache/yourdomain.ssl-access_log" combined
    
    </VirtualHost>
    

    ໃຫ້ແນ່ໃຈວ່າທ່ານໄດ້ປ່ຽນຊື່ໂດເມນທີ່ປ່ຽນແປງຈາກ ServerName, ServerAlias, ErrorLog, CustomLog ຕາມຄວາມ ເໝາະ ສົມ.

    ຂັ້ນຕອນທີ 2: ຕິດຕັ້ງ Lets 'ໃສ່ໃນ FreeBSD

    6. ໃນບາດກ້າວຕໍ່ໄປ, ອອກ ຄຳ ສັ່ງຕໍ່ໄປນີ້ໃນການຕິດຕັ້ງເຄື່ອງມືທີ່ໃຊ້ certbot ທີ່ສະ ໜອງ ໂດຍ Let’s Encrypt, ເຊິ່ງຈະຖືກ ນຳ ໃຊ້ເພື່ອຮັບໃບຢັ້ງຢືນທີ່ບໍ່ເສຍຄ່າ Apache TSL ສຳ ລັບໂດເມນຂອງທ່ານ.

    ໃນຂະນະທີ່ຕິດຕັ້ງ certbot ຊຸດຂອງການກະຕຸ້ນເຕືອນຈະຖືກສະແດງຢູ່ ໜ້າ ຈໍຂອງທ່ານ. ໃຊ້ພາບ ໜ້າ ຈໍຂ້າງລຸ່ມນີ້ເພື່ອ ກຳ ຫນົດຄ່າຜົນປະໂຫຍດຂອງ certbot. ນອກຈາກນີ້, ການລວບລວມແລະຕິດຕັ້ງຜົນປະໂຫຍດຂອງ certbot ອາດຈະໃຊ້ເວລາບາງເວລາ, ຂື້ນກັບຊັບພະຍາກອນຂອງເຄື່ອງຂອງທ່ານ.

    # cd /usr/ports/security/py-certbot
    # make install clean
    

    7. ຫຼັງຈາກຂະບວນການລວບລວມຂໍ້ມູນໄດ້ ສຳ ເລັດແລ້ວ, ອອກ ຄຳ ສັ່ງຂ້າງລຸ່ມນີ້ເພື່ອປັບປຸງຜົນປະໂຫຍດແລະໃບຢັ້ງຢືນທີ່ຂື້ນກັບຄວາມຕ້ອງການຂອງ certbot.

    # pkg install py27-certbot
    # pkg install py27-acme
    

    8. ເພື່ອສ້າງໃບຢັ້ງຢືນ ສຳ ລັບໂດເມນຂອງທ່ານ, ອອກ ຄຳ ສັ່ງດັ່ງທີ່ສະແດງຢູ່ຂ້າງລຸ່ມ. ໃຫ້ແນ່ໃຈວ່າທ່ານໃຫ້ທີ່ຕັ້ງເວັບໄຊທ໌ທີ່ຖືກຕ້ອງທີ່ໄຟລ໌ເວບໄຊທ໌ຂອງທ່ານຖືກເກັບໄວ້ໃນລະບົບແຟ້ມເອກະສານ (DocumentRoot directive ຈາກເອກະສານການຕັ້ງຄ່າໂດເມນຂອງທ່ານ) ໂດຍໃຊ້ -w ທຸງ. ຖ້າທ່ານມີຫລາຍໂດເມນຍ່ອຍເພີ່ມພວກມັນທັງ ໝົດ ພ້ອມກັບທຸງ -d .

    # certbot certonly --webroot -w /usr/local/www/apache24/data/ -d yourdomain.com -d www.yourdomain.com
    

    ໃນຂະນະທີ່ໄດ້ຮັບໃບຢັ້ງຢືນ, ສະ ໜອງ ທີ່ຢູ່ອີເມວ ສຳ ລັບການຕໍ່ອາຍຸໃບຢັ້ງຢືນ, ກົດປຸ່ມເພື່ອຕົກລົງເຫັນດີກັບຂໍ້ ກຳ ນົດແລະເງື່ອນໄຂຂອງ Let’s encryption ແລະ n ເພື່ອບໍ່ແບ່ງປັນທີ່ຢູ່ອີເມວໃຫ້ຄູ່ຮ່ວມງານເຂົ້າລະຫັດ.

    Saving debug log to /var/log/letsencrypt/letsencrypt.log
    Enter email address (used for urgent renewal and security notices) (Enter 'c' to
    cancel):[email 
    There seem to be problems with that address. Enter email address (used for
    urgent renewal and security notices)  If you really want to skip this, you can
    run the client with --register-unsafely-without-email but make sure you then
    backup your account key from /etc/letsencrypt/accounts   (Enter 'c' to cancel):[email 
    
    -------------------------------------------------------------------------------
    Please read the Terms of Service at
    https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.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: n Obtaining a new certificate Performing the following challenges: http-01 challenge for www.domain.com Using the webroot path /usr/local/www/apache24/data for all unmatched domains. Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at /usr/local/etc/letsencrypt/live/www.yourdomain.com/fullchain.pem. Your cert will expire on 2017-11-15. 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 /usr/local/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

    9. ຫຼັງຈາກທີ່ທ່ານໄດ້ຮັບໃບຢັ້ງຢືນ ສຳ ລັບໂດເມນຂອງທ່ານ, ທ່ານສາມາດ ດຳ ເນີນການ ຄຳ ສັ່ງເພື່ອຂຽນລາຍຊື່ສ່ວນປະກອບຂອງໃບຢັ້ງຢືນ (ລະບົບຕ່ອງໂສ້, ກຸນແຈສ່ວນຕົວ, ໃບຢັ້ງຢືນ) ຕາມທີ່ສະແດງຢູ່ໃນຕົວຢ່າງຂ້າງລຸ່ມນີ້.

    # ls -al /usr/local/etc/letsencrypt/live/www.yourdomain.com/
    

    ຂັ້ນຕອນທີ 3: ປັບປຸງໃບຢັ້ງຢືນ Apache TLS ໃນ FreeBSD

    10. ເພື່ອເພີ່ມໃບຢັ້ງຢືນ Let’s Encrypt ໃຫ້ກັບເວັບໄຊທ໌້ຂອງທ່ານ, ເປີດເອກະສານຕັ້ງຄ່າ apache ສຳ ລັບໂດເມນຂອງທ່ານແລະປັບປຸງສາຍຕໍ່ໄປນີ້ເພື່ອສະທ້ອນເສັ້ນທາງຂອງໃບຢັ້ງຢືນທີ່ອອກໃຫ້.

    # nano /usr/local/etc/apache24/sites-available/bsd.lan-ssl.conf
    

    ເພີ່ມສາຍໃບຢັ້ງຢືນ TLS ເຫຼົ່ານີ້:

    SSLCertificateFile "/usr/local/etc/letsencrypt/live/www.yourdomain.com/cert.pem"
    	SSLCertificateKeyFile "/usr/local/etc/letsencrypt/live/www.yourdomain.com/privkey.pem"
    	SSLCertificateChainFile "/usr/local/etc/letsencrypt/live/www.yourdomain.com/fullchain.pem"
    

    11. ສຸດທ້າຍ, ເປີດໃຊ້ເອກະສານການຕັ້ງຄ່າ TLS, ໂດຍການສ້າງເອກະສານເຊື່ອມຕໍ່ ສຳ ລັບເອກະສານການຕັ້ງຄ່າ TLS ຂອງໂດເມນຂອງທ່ານໄປທີ່ໄດເລກະທໍລີທີ່ເປີດໃຊ້ເວັບໄຊທ໌, ກວດເບິ່ງການຕັ້ງຄ່າ Apache ສຳ ລັບຂໍ້ຜິດພາດຂອງ syntax ທີ່ເປັນໄປໄດ້ແລະຖ້າ syntax ບໍ່ຖືກຕ້ອງ, ໃຫ້ restart da da Apache ໂດຍການອອກ ຄຳ ສັ່ງຕໍ່ໄປນີ້.

    # ln -sf /usr/local/etc/apache24/sites-available/bsd.lan-ssl.conf /usr/local/etc/apache24/sites-enabled/
    # apachectl -t
    # service apache24 restart
    

    12. ເພື່ອກວດສອບວ່າການບໍລິການຂອງ Apache ກຳ ລັງຟັງຢູ່ເທິງພອດ HTTPS 443, ອອກ ຄຳ ສັ່ງຕໍ່ໄປນີ້ເພື່ອລົງບັນຊີເຄືອຂ່າຍ httpd.

    # sockstat -4 | grep httpd
    

    13. ທ່ານສາມາດໄປຫາທີ່ຢູ່ໂດເມນຂອງທ່ານຈາກໂປແກຼມທ່ອງເວັບຜ່ານໂປໂຕຄອນ HTTPS ເພື່ອຢືນຢັນວ່າໃບຢັ້ງຢືນ Let’s Encrypt ຖືກ ນຳ ໃຊ້ຢ່າງ ສຳ ເລັດຜົນ.

    https://www.yourdomain.com
    

    14. ເພື່ອໃຫ້ໄດ້ຂໍ້ມູນພິເສດກ່ຽວກັບໃບຢັ້ງຢືນ Let’s Encrypt ອອກຈາກເສັ້ນ ຄຳ ສັ່ງ, ໃຫ້ໃຊ້ ຄຳ ສັ່ງ opensl ດັ່ງຕໍ່ໄປນີ້.

    # openssl s_client -connect www.yourdomain.com:443
    

    15. ທ່ານຍັງສາມາດກວດສອບໄດ້ຖ້າການຈາລະຈອນຖືກເຂົ້າລະຫັດດ້ວຍໃບຢັ້ງຢືນທີ່ຖືກຕ້ອງທີ່ໃຫ້ໂດຍ Let’s Encrypt CA ຈາກອຸປະກອນມືຖືດັ່ງທີ່ສະແດງຢູ່ໃນພາບ ໜ້າ ຈໍມືຖືລຸ່ມນີ້.

    ຫມົດເທົ່ານີ້! ລູກຄ້າສາມາດເຂົ້າເບິ່ງເວັບໄຊທ໌ຂອງເຈົ້າໄດ້ຢ່າງປອດໄພ, ເພາະວ່າການຈະລາຈອນທີ່ໄຫລວຽນລະຫວ່າງເຊີບເວີແລະໂປແກຼມທ່ອງເວັບຂອງລູກຄ້າຖືກເຂົ້າລະຫັດ. ສຳ ລັບ ໜ້າ ວຽກທີ່ສັບສົນກວ່າກ່ຽວກັບຜົນປະໂຫຍດຂອງ certbot ເຂົ້າເບິ່ງທີ່ລິງຕໍ່ໄປນີ້: https://certbot.eff.org/