Giunsa Pag-secure ang Apache gamit ang SSL ug Atong I-encrypt sa FreeBSD


Sa kini nga panudlo mahibal-an namon kung giunsa ang pag-secure sa Apache HTTP server nga adunay mga sertipiko sa TLS/SSL nga gitanyag sa Let's Encrypt sa FreeBSD 11.x. Sakup usab namon kung giunsa ang pag-automate sa proseso sa pagbag-o sa sertipiko alang sa Lets' Encrypt.

Ang mga sertipiko sa TLS/SSL gigamit sa Apache web server aron ma-encrypt ang komunikasyon tali sa mga end node, o mas ordinaryo tali sa server ug kliyente aron makahatag og seguridad. Ang Let's Encrypt naghatag ug certbot command line utility, nga usa ka aplikasyon nga makapadali sa paagi nga makakuha ka ug kasaligang mga sertipiko nga libre.

  1. Pag-instalar sa FreeBSD 11.x
  2. 10 ka Butang nga Buhaton Human sa FreeBSD Installation
  3. Unsaon Pag-instalar sa Apache, MariaDB ug PHP sa FreeBSD

Lakang 1: I-configure ang Apache SSL sa FreeBSD

1. Sa dili pa magsugod sa pag-instalar sa certbot utility ug paghimo sa TSL configuration file para sa Apache, paghimo una og duha ka lahi nga direktoryo nga ginganlan og mga site-available ug sites-enabled sa Apache root configuration directory pinaagi sa pag-isyu sa ubos nga mga sugo.

Ang katuyoan niining duha ka mga direktoryo mao ang pagpadali sa pagdumala sa virtual hosting configuration sa sistema, nga walay pag-usab sa nag-unang Apache httpd.conf configuration file sa matag higayon nga magdugang kami og bag-ong virtual host.

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

2. Human nimo mabuhat ang duha ka direktoryo, ablihi ang Apache httpd.conf file gamit ang text editor ug idugang ang mosunod nga linya duol sa katapusan sa file sama sa gihulagway sa ubos.

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

Idugang ang mosunod nga linya:

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

3. Sunod, i-enable ang TLS module para sa Apache pinaagi sa paghimo sa mosunod nga bag-ong file nga ginganlan og 020_mod_ssl.conf sa modules.d directory nga adunay mosunod nga sulod.

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

Idugang ang mosunod nga mga linya sa file 020_mod_ssl.conf.

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

4. Karon, uncomment ang SSL module gikan sa /usr/local/etc/apache24/httpd.conf file pinaagi sa pagtangtang sa hashtag gikan sa sinugdanan sa mosunod nga linya sama sa gihulagway sa ubos:

LoadModule ssl_module libexec/apache24/mod_ssl.so

5. Sunod, paghimo sa TLS configuration file para sa imong domain sa sites-available directory, mas maayo nga adunay ngalan sa imong domain, ingon sa gipakita sa ubos nga kinutlo:

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

Idugang ang mosunod nga configuration sa virtualhost sa pag-file sa 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>

Siguroha nga imong ilisan ang domain name variable gikan sa ServerName, ServerAlias, ErrorLog, CustomLog nga mga pahayag sumala niana.

Lakang 2: I-install ang Lets'Encrypt sa FreeBSD

6. Sa sunod nga lakang, i-isyu ang mosunod nga sugo aron ma-install ang certbot utility nga gihatag sa Let's Encrypt, nga gamiton aron makakuha og Apache TSL free certificates para sa imong domain.

Samtang nag-instalar sa certbot usa ka serye sa prompt ang ipakita sa imong screen. Gamita ang screenshot sa ubos aron ma-configure ang certbot utility. Usab, ang pag-compile ug pag-install sa certbot utility mahimong magdugay, depende sa imong mga kahinguhaan sa makina.

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

7. Human mahuman ang proseso sa pag-compile, i-issue ang ubos nga sugo aron ma-update ang certbot utility ug certbot gikinahanglang dependencies.

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

8. Aron makamugna og sertipiko alang sa imong domain, i-isyu ang sugo sama sa gihulagway sa ubos. Siguruha nga imong gihatag ang husto nga lokasyon sa webroot diin ang imong mga file sa website gitipigan sa file system (direktiba sa DocumentRoot gikan sa imong domain configuration file) gamit ang -w nga bandila. Kung aduna kay daghang mga subdomain idugang silang tanan gamit ang -d nga bandera.

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

Samtang nagkuha sa sertipiko, paghatag og email address alang sa pag-renew sa sertipiko, pindota ang a aron mouyon sa Let's Encrypt terms and conditions ug n aron dili ipaambit ang email address Let's Encrypt partners.

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. Human nimo makuha ang mga sertipiko alang sa imong domain, mahimo nimong ipadagan ang ls nga sugo aron malista ang tanang mga sangkap sa sertipiko (kadena, pribadong yawe, sertipiko) sama sa gipakita sa ubos nga pananglitan.

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

Lakang 3: I-update ang Apache TLS Certificates sa FreeBSD

10. Aron madugangan ang Let's Encrypt nga mga sertipiko sa imong website, ablihi ang apache configuration file alang sa imong domain ug i-update ang mosunod nga mga linya aron mapakita ang dalan sa gi-isyu nga mga sertipiko.

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

Idugang kini nga mga linya sa sertipiko sa 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. Sa katapusan, pagana ang TLS configuration file, pinaagi sa paghimo ug symlink para sa imong domain TLS configuration file ngadto sa sites-enabled directory, susiha ang Apache configurations alang sa posibleng syntax errors ug, kon OK ra ang syntax, i-restart ang Apache daemon pinaagi sa pag-isyu sa ubos nga mga sugo.

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

12. Aron masusi kung ang serbisyo sa Apache naminaw sa HTTPS port 443, i-isyu ang mosunod nga sugo aron ilista ang httpd network sockets.

# sockstat -4 | grep httpd

13. Mahimo ka nga mag-navigate sa imong adres sa domain gikan sa usa ka browser pinaagi sa protocol sa HTTPS aron makumpirma nga ang mga sertipiko sa Let's Encrypt malampuson nga gigamit.

https://www.yourdomain.com

14. Aron makakuha og dugang nga impormasyon mahitungod sa gi-isyu nga Let's Encrypt certificate gikan sa command line, gamita ang openssl nga sugo sama sa mosunod.

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

15. Mahimo usab nimong pamatud-an kung ang trapiko gi-encrypt gamit ang usa ka balido nga sertipiko nga gihatag sa Let's Encrypt CA gikan sa usa ka mobile device sama sa gihulagway sa ubos nga screenshot sa mobile.

Kana lang! Ang mga kliyente mahimo na nga makabisita sa imong website nga luwas, tungod kay ang trapiko nga nagdagayday tali sa server ug browser sa kliyente gi-encrypt. Alang sa mas komplikado nga mga buluhaton mahitungod sa certbot utility bisitaha ang mosunod nga link: https://certbot.eff.org/