AWS EC2 amazon linux2 nginx 에 HTTPS(secure) 붙이기

chichi·2023년 1월 10일
0

AL2 에 nginx 를 올리는 방법은 인터넷 검색을 통해 찾을 수 있었지만, letsencrypt 를 통해 ssl을 붙이는 방법은 알려주는 곳이 없었다. (있었는데 실행되지 않았다.) 그래서, 현재 기준 최신 AL2 에서 nginx 에 ssl 을 붙이는 방법을 쓰게 되었다.

sudo yum install snapd # 안된다
sudo yum install epel-release # 역시 안된다.

# 대신 AL2 는 아래 명령어를 추천해준다. 그대로 설치하자.
sudo amazon-linux-extras install epel

# nginx 실행중일 경우 에러가 난다. 잠시 꺼주고 다시 실행
sudo yum install snapd
sudo yum install -y certbot
sudo yum install certbot-nginx

sudo certbot --nginx
# email: ~~@~~.~~
# Term of service agreement: Y/N

# 이미 nginx 를 통해 proxy 를 적용할 경우 어떤 곳에 적용할지 묻는다.
# 전부 다 선택했다. (서버 3개라서 1,2,3)
# Which names would you like to activate HTTPS for?
Requesting a certificate for [domainA] and 2 more domains
Performing the following challenges:
http-01 challenge for [domainA]
http-01 challenge for [domainB]
http-01 challenge for [domainC]
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/[domainA].conf
Deploying Certificate to VirtualHost /etc/nginx/conf.d/[domainB].conf
Deploying Certificate to VirtualHost /etc/nginx/conf.d/[domainC].conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/[domainA].conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/[domainB].conf
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/[domainC].conf

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled
https://[domainA], https://[domainB], and
https://[domainC]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Subscribe to the EFF mailing list (email:[admin email]).

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/[domainA]/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/[domainA]/privkey.pem
   Your certificate will expire on 2022-12-28. 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"
 - 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

nginx 서버를 재실행한다. 잘 동작하는지 확인한다.

혹시 동작하지 않을 경우 nginx.conf 에 가서 서버네임을 다음과 같이 수정한다.

참고문서
1. installing snap on centos
2.AWS linux2에서 Nginx로 Let's Encrypt 사용하기

profile
번역글 위주로 다루려 합니다. 오역 및 기타 사항은 해당 게시글에 댓글로 남겨주시면 답변드리겠습니다. 좋은 하루 되세요!

0개의 댓글