AWS 서버 구축 - https 적용

2021. 1. 25. 16:39Server

반응형

https://twpower.github.io/44-set-free-https-by-using-letsencrypt

 

[Nginx] Let's Encrypt를 통해 Nginx에서 무료로 https 설정하기

Practice makes perfect!

twpower.github.io

위 최신 자료 참고

 

1. CertBot 설치하기 

* Certbot은 Let’s Encrypt 인증서를 자동으로 발급 및 갱신을 해주는 봇 프로그램이다.

sudo su #/var/www/html 안에서 
apt-get update
apt-get install software-properties-common
add-apt-repository universe
add-apt-repository ppa:certbot/certbot
apt-get update

apt install certbot
apt install python-certbot-nginx #nginx와 사용할때 

certbot --nginx

 

(앞으로 나오는 질문들에 대한 응답 모음 )

Saving debug log to /var/log/letsencrypt/letsencrypt.log

Plugins selected: Authenticator nginx, Installer nginx

Enter email address (used for urgent renewal and security notices) (Enter 'c' to

cancel): info@hometek.co.kr

  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Please read the Terms of Service at

[https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf.](https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf.) You must

agree in order to register with the ACME server at

https://acme-v02.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 our work

encrypting the web, EFF news, campaigns, and ways to support digital freedom.

  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

(Y)es/(N)o: Y

No names were found in your configuration files. Please enter in your domain

name(s) (comma and/or space separated)  (Enter 'c' to cancel): visithome.shop www.visithome.shop

Obtaining a new certificate

Performing the following challenges:

http-01 challenge for visithome.shop

http-01 challenge for www.visithome.shop

Waiting for verification...

Cleaning up challenges

Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/default

Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/default

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.

  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

1: No redirect - Make no further changes to the webserver configuration.

2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for

new sites, or if you're confident your site works on HTTPS. You can undo this

change by editing your web server's configuration.

  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/default

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/default

  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Congratulations! You have successfully enabled https://visithome.shop and

https://www.visithome.shop

You should test your configuration at:

https://www.ssllabs.com/ssltest/analyze.html?d=visithome.shop

https://www.ssllabs.com/ssltest/analyze.html?d=www.visithome.shop

  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:

- Congratulations! Your certificate and chain have been saved at:

/etc/letsencrypt/live/visithome.shop/fullchain.pem

Your key file has been saved at:

/etc/letsencrypt/live/visithome.shop/privkey.pem

Your cert will expire on 2020-01-25. To obtain a new or tweaked

version of this certificate in the future, simply run certbot again

with the "certonly" option. To non-interactively renew all of

your certificates, run "certbot renew"

- Your account credentials have been saved in your Certbot

configuration directory at /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

 

완료 

 

2. 미래에 인증서 갱신을 해주기 위해 "certonly" 옵션을 주고 다시한번 실행한다.

certbot certonly --nginx

(앞으로 나오는 질문들에 대한 응답 모음 )

manager@manager-PC:~$ sudo certbot certonly --apache

Saving debug log to /var/log/letsencrypt/letsencrypt.log

Plugins selected: Authenticator apache, Installer apache

Which names would you like to activate HTTPS for?

  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

1: visithome.shop

2: www.visithome.shop

  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Select the appropriate numbers separated by commas and/or spaces, or leave input

blank to select all options shown (Enter 'c' to cancel): 1 2

Cert not yet due for renewal

You have an existing certificate that has exactly the same domains or certificate name you requested and isn't close to expiry.

(ref: /etc/letsencrypt/renewal/visithome.shop.conf)

What would you like to do?

  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

1: Keep the existing certificate for now

2: Renew & replace the cert (limit ~5 per 7 days)

  • - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Renewing an existing certificate

IMPORTANT NOTES:

- Congratulations! Your certificate and chain have been saved at:

/etc/letsencrypt/live/visithome.shop/fullchain.pem

Your key file has been saved at:

/etc/letsencrypt/live/visithome.shop/privkey.pem

Your cert will expire on 2020-01-25. 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

 

 

3. 자동갱신

유효 기간이 3개월이므로 3개월 마다 자동 갱신을 해주어야한다.

만료 날짜에 신경쓰기 싫을때는 매일 갱신하도록   /etc/crontab에 다음과 같이 추가한다.

(매일 0시 0분에 실행한다. 정확한 만료 날짜를 알면 정확하게 지정한다.)

 

vi /etc/crontab
0  0 * * * root certbot -q renew --nginx >> /var/log/letscript.renewal.log 2>&1 #추가
service cron restart

 

 

4. 설정파일 자동수정

설치된 인증서는 /etc/letsencrypt/live/lilyspace.shop에서 확인할 수 있다.

 

 

실행 결과 nginx의 환경파일(/etc/nginx/sites-available/defaut)이 자동 수정된다.

vi /etc/nginx/sites-available/default

(vi /etc/nginx/sites-enabled/default vs vi /etc/nginx/sites-available/default 차이 

차이는 잘모르겠지만 주로 available을 쓴다. )

 

5. https 적용 확인

lilyspace.shop/

<참고자료>

https://hometek.co.kr/Linux/show/293e5f2e-6725-40a7-acb9-c63325e91f46

반응형