본문 바로가기
NGINX

[실습 성공] NGINX 서브도메인 - 무료 SSL 인증서 & HTTPS 구성

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

 


## 서브도메인 HTTPS 인증서 설치

1. certbot certonly --standalone -d opt.koaXXX.ga
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for opt.koaXXX.ga
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/opt.koaXXX.ga/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/opt.koaXXX.ga/privkey.pem
   Your cert will expire on 2021-08-29. 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"
 - 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
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>




2. opt.koaXXX.ga 접속 환경 설정
- /etc/nginx/nginx.conf 수정
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
        upstream opt {
              server 54.180.XXX.XXX:8080;    # (톰캣서버 IP 지정)
        }
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>


- nginx 가 이제 인증서가 있고 HTTPS를 사용하려고 한다는 것을 인식하도록 설정
- vi /etc/nginx/sites-available/opt  (맨 하단에 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 opt.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 opt.koaXXX.ga;

    ssl_certificate /etc/letsencrypt/live/opt.koaXXX.ga/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/opt.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://opt;

           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 에러 발생)
   }
}
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>



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

- nginx 재시작
  : systemctl restart nginx


4. curl 로 접속 확인   (정상동작 확인)
- curl -v opt.koaXXX.ga
- Location: https://opt.koaXXX.ga/  확인

 

 

 

 

 

 

 

반응형

'NGINX' 카테고리의 다른 글

nginx + tomcat 클러스터링 구성  (0) 2021.06.10
Nginx HTTPS 설정  (2) 2021.06.02
[실습 성공] 무료 SSL 인증서 & HTTPS 구성  (0) 2021.05.31
[에러] HTTPS 인증서 발행시...  (0) 2021.05.31
[실습] AWS Nginx & TOMCAT 연동  (0) 2021.05.28

댓글