본문 바로가기
NGINX

[실습 성공] 무료 SSL 인증서 & HTTPS 구성

by SAMSUNG CLOUD-OKY 2021. 5. 31.
반응형



1. certbot 설치
sudo apt install certbot

## 사전 nginx 80포트 중지 및 , 방화벽 오픈 필요 
2. certbot 으로 인증서 생성
- 도메인 이름 설정 : -d koaXXX.ga
certbot certonly --standalone -d koaXXX.ga

- 이메일 주소와 인증서 만료시기를 등록
- 약관에 Agree (A 입력)
- 이메일 공유 (Y 입력)


- /etc/letsencrypt 폴더를 백업할 것
- /etc/letsencrypt 디렉토리는 두개의 키를 모두 가지고 있음


3. 인증서 백업 하기
cp -r /etc/letsencrypt/ /home/ubuntu/
  : cd /home/ubuntu/
  : tar czf letsencrypt.tar.gz letsencrypt/



4. nginx 구성파일 편집

 

- /etc/nginx/nginx.conf 수정
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        upstream www {
              server 3.37.XXX.XXX:8080;     # (톰캣서버 IP지정)
        }

        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

 

 

 


- nginx 가 이제 인증서가 있고 HTTPS를 사용하려고 한다는 것을 인식하도록 설정
- vi /etc/nginx/sites-available/www  (맨 하단에 443 포트 이용 내용을 붙여넣기)

- 하기 내용을 재수정
  : ssl_certificate  위치 수정
  : ssl_certificate_key 위치 수정
  : ssl_dhparam 주석 처리
  : ssl_trusted_certificate  삭제할 것
  : resolver 8.8.8.8;     (구글 DNS 설정)
  : server_name 추가


<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
server {
        listen 80;
        listen [::]:80;

        server_name www.koaXXX.ga koaXXX.ga;

        return 301 https://$host$request_uri; 


#       root /var/www/example.com;
#       index index.html;
}


server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    server_name www.koaXXX.ga koaXXX.ga;

    ssl_certificate /etc/letsencrypt/live/koaXXX.ga/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/koaXXX.ga/privkey.pem;
    ssl_session_timeout 1d;
    ssl_session_cache shared:MozSSL:10m;  # about 40000 sessions
    ssl_session_tickets off;

    # curl https://ssl-config.mozilla.org/ffdhe2048.txt > /path/to/dhparam
    # ssl_dhparam /path/to/dhparam;

    # intermediate configuration
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
    ssl_prefer_server_ciphers off;

    # HSTS (ngx_http_headers_module is required) (63072000 seconds)
    add_header Strict-Transport-Security "max-age=63072000" always;

    # OCSP stapling
    ssl_stapling on;
    ssl_stapling_verify on;

    # verify chain of trust of OCSP response using Root CA and Intermediate certs
    # ssl_trusted_certificate /path/to/root_CA_cert_plus_intermediates;

    # replace with the IP address of your resolver
    resolver 8.8.8.8;


    location / {
           proxy_pass http://www;

           proxy_set_header    HOST $host;
           proxy_set_header    X-Real-IP $remote_addr;
           proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header    X-Forwarded-Proto $scheme;

           proxy_redirect  off;
           charset utf-8;

           index index.jsp;

#          try_files $uri $uri/ =404;   (넣으면 NGINX 에러 발생)
   }
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


5. 추가 nginx 구성파일 편집  (80 -> 443 리다이렉트 편집)
- return 301 https://$host$request_uri;     입력

- nginx 재시작
  : systemctl restart nginx


6. curl 로 접속 확인
- curl -v koaXXX.ga
- Location: https://koaXXX.ga/  확인


 

 

 

 


## HTTPS 인증서 재활용

root@/home/ubuntu# tar xzvf letsencrypt.tar.gz

root@/home/ubuntu# cp -r letsencrypt/ /etc/

 

 

 

 

 

 

 

 

반응형

댓글