댓글 목록

localhost에 인증서(SSL) 설정하기

페이지 정보

작성자 운영자 작성일 20-10-27 21:54 조회 1,456 댓글 0

동영상 강좌는 유튜브 채널 '웹학교'를 이용하시기 바랍니다.

최근 현대 브라우저는 SSL을 거의 의무사항으로 요구합니다.

어떤 프로그램은 SSL이 아니면 설정이 되지 않는 경우도 있습니다.

브라우저와 사용자간에 주고 받는 정보를 제3자가 엿보지 않는 것도록 https://를 적용하는 것은 일반화되어 가고 있습니다.

SSL은 공인 도메인에 대하여 인증해 줍니다.

그런데 localhost에서 개발을 할 때는 어떻게 해야 할까요?


다행히도 localhost에도 사설로 https를 적용할 수 있는 솔루션들이 하나 둘 나오고 있습니다.


그 중에서 mkcert를 설치하고 xampp상황에서 여러 localhost 주소에 대하여 SSL을 적용해 보겠습니다.


https://github.com/FiloSottile/mkcert 

https://mkcert.dev/


더 많은 관련 정보는 https://365ok.co.kr/tj/okdown/7804 를 참조하세요.


윈도우 환경에서 mkcert를 설치하기 위해서는 윈도우 패키지 관리자 Chocolatey를 사용해야 합니다.


1. Chocolatey 설치하기


https://chocolatey.org/install 접속하기
 

1) 윈도우10에 기본적으로 제공하는 powershell.exe을 관리자로 실행합니다.


2) 아래 명령을 실행합니다.
>Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

2. Chocolatey를 이용하여 mkcert를 설치합니다.

>choco install mkcert

3. 도메인 인증서를 추가합니다.
>mkcert localhost demo2.localhost ok.localhost

4. pem 파일을 옮깁니다.

 localhost+2.pem => c:\xampp\apache\conf/ssl.crt

 localhost+2-key.pem => c:\xampp\apache\conf/ssl.key


5. Apache 설정파일에 SSL 반영

c:\xampp\apache\conf\extra\httpd-ssl.conf


<VirtualHost _default_:443>

 

#   General setup for the virtual host

DocumentRoot "C:/xampp/htdocs"

ServerName localhost:443

ServerAdmin abc@abc.com

ErrorLog "C:/xampp/apache/logs/error.log"

TransferLog "C:/xampp/apache/logs/access.log"

 

#   SSL Engine Switch:

#   Enable/Disable SSL for this virtual host.

SSLEngine on

 

SSLCertificateFile "conf/ssl.crt/localhost+2.pem"

 

SSLCertificateKeyFile "conf/ssl.key/localhost+2-key.pem"

 

...

 

</VirtualHost>   


6. Apache 재시작


** 주소 줄에 https://를 꼭 입력해야 할 경우만 반영될 때

c:\xampp\apache\conf\extra\httpd-xampp.conf 파일을 열고 아래 코드 추가


<IfModule mod_rewrite.c>


    RewriteEngine On


    # Redirect /xampp folder to https

    RewriteCond %{HTTPS} !=on

    RewriteCond %{REQUEST_URI} xampp

    RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]


    # Redirect /phpMyAdmin folder to https

    RewriteCond %{HTTPS} !=on

    RewriteCond %{REQUEST_URI} phpmyadmin

    RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]


    # Redirect /security folder to https

    RewriteCond %{HTTPS} !=on

    RewriteCond %{REQUEST_URI} security

    RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]


    # Redirect /webalizer folder to https

    RewriteCond %{HTTPS} !=on

    RewriteCond %{REQUEST_URI} webalizer

    RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]


    # Redirect /folder_name folder to https

    RewriteCond %{HTTPS} !=on

    RewriteCond %{REQUEST_URI} folder_name

    RewriteRule ^(.*) https://%{SERVER_NAME}$1 [R,L]

</IfModule>


댓글목록 0

등록된 댓글이 없습니다.