nginx, apache에서 SSL, HTTPS 보안 인증서 적용과 리디렉션 하기

이전의 글 무료 SSL 인증서 발급 / 윈도우 Let’s Encrypt 자동 갱신, 개념 이해 에서 SSL 보안 인증서를 받았다면 이제 웹서버에 적용해 보도록 하겠습니다. 

win-acme프로그램을 통해 SSL 보안 인증서를 정상적으로 발급 받았다는 전제 하에 윈도우 환경에 설치한 nginx 와 apache 두 가지 웹서버에 SSL을 적용해 보겠습니다.

nginx 에 SSL 적용하기

nginx의 경우 nginx.conf 파일을 수정 합니다.

server {
    listen       443 ssl http2;    # SSL 기본 포트는 443 입니다.
    server_name  ex-domain.com www.ex-domain.com;    #서버 이름은 예시 입니다.
    charset utf-8;
  
    ssl_certificate c:/nginx-server/ssl/ex-domain.com-chain.pem;
    ssl_certificate_key c:/nginx-server/ssl/ex-domain.com-key.pem;
# 여기 위 부분 인증서 경로와 파일명을 본인의 것으로 입력해 주세요.
    ssl_session_timeout 10m;
    ssl_protocols TLSv1.3 TLSv1.2;
    ssl_ciphers   'ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS';
    ssl_prefer_server_ciphers on;
    ssl_stapling on;
    ssl_stapling_verify on; 
 location / {
       root   html;
       index  index.php index.htm index.html;
    }
}

nginx 는 서버 블록 안에 위와 같이 SSL 명령을 추가해 주시면 됩니다. 모두 다 되었으면 웹 서버를 재시작 합니다.

잘 되었는지 확인해 봅시다. 웹 브라우저 창에 http:// 대신 https:// 를 붙였을때 제대로 접속하는지 확인합니다.

ahpache 에 SSL 적용하기

아파치 파일은 httpd.conf 에서 수정하시면 됩니다.

xampp환경에서는 extra/httpd-ssl.conf 에서 수정하세요. 아파치 가상 호스트를 굴리시는 분은 두번째 도메인 부터는 httpd-vhosts.conf 에서 입력하시면 됩니다.

사실 모두 다 httpd.conf로 불려 들어가는 파일들이라 extra 폴더 어디에 적든 상관은 없습니다. 다만 명령문이 겹칠 우려가 있긴하지만요.

<VirtualHost _default_:443>
DocumentRoot "/xampp/htdocs"		# root 경로입니다. 본인의 서버 환경에 맞춰주세요.
ServerName www.ex-domain.com		# 도메인 이름을 적어주세요.
ServerAdmin admin@mymail.kr     # 서버 관리자 이메일 주소입니다. 옵션입니다.
ErrorLog "/xampp/apache/logs/error.log"       # 에러 로그가 기록되는 위치입니다.
TransferLog "/xampp/apache/logs/access.log"   # Transfer 로그가 기록되는 위치입니다.
SSLEngine on
SSLCertificateFile "c:/apache-server/ssl/ex-domain.com-crt.pem"
SSLCertificateKeyFile "c:/apache-server/ssl/ex-domain.com-key.pem"
SSLCertificateChainFile "c:/apache-server/ssl/ex-domain.com-chain.pem"
# 여기 위 부분 인증서 경로와 파일명을 본인의 것으로 입력해 주세요.

모두 다 되었으면 웹 서버를 재시작 합니다.

잘 되었는지 확인해 봅시다. 웹 브라우저 창에 http:// 대신 https:// 를 붙였을때 제대로 접속하는지 확인합니다.

http 주소 https 리디렉팅하기

SSL 설정을 완료 하면 “http주소”와 “https주소” 두 개 모두 접속할 수 있게됩니다. 이 경우 http는 서비스 종료하고 https로만 서비스 하는 것을 권장합니다.

아래의 방법을 사용하면 사용자가 http로 접속했을 때 자동으로 https로 연결 할 수 있습니다.

nginx 에서 리디렉팅


server {
    server_name ex-domain.com www.ex-domain.com;   # 본인의 도메인을 적어주세요.
    listen 80;
    if ($host = ex-domain.com) {
        return 301 https://www.$host$request_uri;  
	} 
    if ($host = www.ex-domain.com) {
        return 301 https://$host$request_uri;
	} 
}

위와 같이 서버 블록 80번 포트 설정(listen 80;)에 return 301 태그를 붙여서 리디렉션 해줍니다.

구글과 같은 검색엔진은 ex-domain.com 주소와  www.ex-domain.com 주소를 다른 주소로 인식합니다. 때문에 www 사용 여부를 리디렉션에서도 정확히 지정해 주셔야 합니다.

위의 예시는 www를 붙이던 안붙이던 모두 www를 붙여 리디렉션 하도록 하였습니다.

apache 에서 리디렉팅

<VirtualHost *:80>
RewriteEngine On
RewriteRule (.*) https://www.ex-domain.com/$1  [R=301,L]
</VirtualHost>

아파치 에서는 RewriteEngine 을 활성화에서 301 리디렉션 합니다.

<VirtualHost *:443>
    ServerName www.ex-domain.com
    ServerAlias  *.ex-domain.com, ex-domain.com
    ...
    ... # 이하 443포트 설정 계속
</VirtualHost>

만약 위의 nginx 사례처럼 도메인에 www를 붙여 주소를 통일 하려면 위와 같이 <VirtualHost *:443> 설정에 ServerAlias 문구를 추가해 주시면 됩니다.

설정이 완료 되었으면 서버를 재시작 합니다.

이제 테스트 해볼 시간입니다. 우선 웹 브라우저 로컬 캐시를 삭제해 줍니다. 그리고 주소창에 http://로 접속했을 때 자동으로 https://로 연결되는지 확인 합니다.

오늘은 여기까지 입니다. 수고하셨습니다

“nginx, apache에서 SSL, HTTPS 보안 인증서 적용과 리디렉션 하기”에 대한 3개의 생각

  1. I am so glad I found Berlusconi Market (Berlusconimarket.com) again. They are back in business, and the experience is just as smooth as it used to be. I just got my fentanyl, and it is perfect. Everyone I know who used to shop here missed Berlusconi Market (Berlusconimarket.com) while they were gone. It is great to have them back.

    답글
  2. Guys, I have to share this. You all remember Berlusconimarket.com, right? Back in the day, it was unmatched, but things went downhill a little bit years ago. Seriously, I was about to give up on them, but I just got my package today and… wow. The quality is legitimately high, which is the biggest thing. They’ve clearly overhauled their system—it feels like they’re only sourcing from really legit, verified vendors now. If you guys were considering checking them out again, this might be the one. Highly recommend giving them a shot!”

    답글
  3. I really appreciated how you connected the scientific ideas to everyday observations without oversimplifying them. The clear explanation of why evidence can evolve over time made the topic feel both approachable and exciting.

    답글

댓글 남기기