웹사이트 검색

SSL로 Apache를 보호하는 방법과 FreeBSD에서 암호화하자


이 튜토리얼에서는 FreeBSD 11에서 Let's Encrypt가 제공하는 TLS/SSL 인증서로 Apache HTTP 서버를 보호하는 방법을 알아봅니다. x. 또한 Lets' Encrypt에 대한 인증서 갱신 프로세스를 자동화하는 방법도 다룹니다.

추가 읽기: FreeBSD에 Nginx용 Let’s Encrypt 설치

TLS/SSL 인증서는 보안을 제공하기 위해 Apache 웹 서버에서 최종 노드 간 또는 보다 일반적인 서버와 클라이언트 간의 통신을 암호화하는 데 사용됩니다. Let’s Encrypt는 신뢰할 수 있는 인증서를 무료로 얻을 수 있는 방법을 촉진할 수 있는 애플리케이션인 certbot 명령줄 유틸리티를 제공합니다.

요구사항:

  1. FreeBSD 11.x 설치
  2. FreeBSD 설치 후 해야 할 10가지 일
  3. FreeBSD에 Apache, MariaDB, PHP를 설치하는 방법

1단계: FreeBSD에서 Apache SSL 구성

1. certbot 유틸리티 설치를 시작하고 Apache용 TSL 구성 파일을 만들기 전에 먼저 sites-available이라는 두 개의 고유한 디렉터리를 만듭니다. 아래 명령을 실행하여 Apache 루트 구성 디렉터리에서 >sites-enabled를 활성화합니다.

이 두 디렉토리의 목적은 새 가상 호스트를 추가할 때마다 기본 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. 다음으로 modules.d<에 020_mod_ssl.conf라는 새 파일을 생성하여 Apache용 TLS 모듈을 활성화합니다. 디렉토리에 다음 내용이 포함됩니다.

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. 이제 처음부터 해시태그를 제거하여 /usr/local/etc/apache24/httpd.conf 파일에서 SSL 모듈의 주석 처리를 제거합니다. 아래 그림과 같이 다음 줄 중 하나입니다.

LoadModule ssl_module libexec/apache24/mod_ssl.so

5. 다음으로 sites-available 디렉토리에 도메인에 대한 TLS 구성 파일을 생성합니다. 가능한 경우 도메인 이름을 사용하여 다음과 같이 하십시오. 아래 발췌:

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

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단계: FreeBSD에 Lets'Encrypt 설치

6. 다음 단계에서는 Let's Encrypt에서 제공하는 certbot 유틸리티를 설치하기 위해 다음 명령을 실행합니다. 도메인에 대한 Strong>Apache TSL 무료 인증서.

certbot을 설치하는 동안 일련의 프롬프트가 화면에 표시됩니다. 아래 스크린샷을 사용하여 certbot 유틸리티를 구성하세요. 또한 시스템 리소스에 따라 certbot 유틸리티를 컴파일하고 설치하는 데 다소 시간이 걸릴 수 있습니다.

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

7. 컴파일 프로세스가 완료된 후 certbot 유틸리티 및 certbot 필수 종속성을 업데이트하려면 아래 명령을 실행하세요.

pkg install py27-certbot
pkg install py27-acme

8. 도메인에 대한 인증서를 생성하려면 아래 그림과 같이 명령을 실행하세요. -w 플래그를 사용하여 웹사이트 파일이 파일 시스템에 저장된 올바른 웹루트 위치(도메인 구성 파일의 DocumentRoot 지시어)를 제공했는지 확인하세요. 하위 도메인이 여러 개인 경우 -d 플래그를 사용하여 모두 추가하세요.

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

인증서를 획득하는 동안 인증서 갱신을 위한 이메일 주소를 제공하고, Let's Encrypt 이용 약관에 동의하려면 a를 누르고, Let’s Encrypt 파트너와 이메일 주소를 공유하지 않으려면 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 명령을 실행할 수 있습니다.

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

3단계: FreeBSD에서 Apache TLS 인증서 업데이트

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 구성 파일에 대한 심볼릭 링크를 sites-enabled 디렉토리에 생성하여 TLS 구성 파일을 활성화하고 Apache 구성에서 가능한 구문 오류를 확인하고, 구문이 정상이면 아래 명령을 실행하여 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. Let’s Encrypt 인증서가 성공적으로 적용되었는지 확인하기 위해 HTTPS 프로토콜을 통해 브라우저에서 도메인 주소로 이동할 수 있습니다.

https://www.yourdomain.com

14. 발급된 Let’s Encrypt 인증서에 대한 추가 정보를 명령줄에서 얻으려면 다음과 같이 openssl 명령을 사용하십시오.

openssl s_client -connect www.yourdomain.com:443

15. 아래 모바일 스크린샷과 같이 모바일 기기에서 Let's Encrypt CA에서 제공하는 유효한 인증서를 사용하여 트래픽이 암호화되었는지 확인할 수도 있습니다.

그게 다야! 서버와 클라이언트 브라우저 사이에 흐르는 트래픽이 암호화되므로 클라이언트는 이제 안전하게 웹 사이트를 방문할 수 있습니다. certbot 유틸리티와 관련된 더 복잡한 작업을 보려면 다음 링크를 방문하세요: https://certbot.eff.org/