BackEnd๐ŸŒฑ/Etc

๊ฐ€๋น„์•„ + Linux + Nginx + Cerbot/SSL์„ ํ™œ์šฉํ•œ https ์„ค์ •

dkswnkk 2022. 12. 5. 04:33

์„œ๋ก 

๊ฐ€๋น„์•„ + Linux + Nginx + Cerbot/SSL์„ ํ™œ์šฉํ•œ https ์„ค์ •์— ๋Œ€ํ•ด ๋ฌธ์„œํ™”ํ•˜๊ณ ์ž ๊ธ€์„ ์ž‘์„ฑํ•˜๊ฒŒ ๋˜์—ˆ์Šต๋‹ˆ๋‹ค.

ํ™˜๊ฒฝ

  • ์›น ์„œ๋ฒ„: Nginx
  • ์ธ์ฆ์„œ ๋ฐœ๊ธ‰: Cerbot/SSL
  • ์šด์˜์ฒด์ œ: Amazone Linux
  • ๋„๋ฉ”์ธ ๊ตฌ๋งค: ๊ฐ€๋น„์•„

๋ชฉ์ฐจ

  1. ๋„๋ฉ”์ธ ๊ตฌ๋งค ๋ฐ ์„ค์ •
  2. Nginx ์„ค์น˜ ๋ฐ ์ˆ˜์ •
  3. Cetbot ์„ค์น˜ ๋ฐ SSL ๋ฐœ๊ธ‰
  4. Proxy ์„ค์ •
  5. ์ธ์ฆ์„œ ์ž๋™ ๊ฐฑ์‹ (์„ ํƒ)

1. ๋„๋ฉ”์ธ ๊ตฌ๋งค

๋จผ์ € ๋„๋ฉ”์ธ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. ๋„๋ฉ”์ธ์€ ์‚ฌ๋žŒ๋“ค์ด ์›ํ•˜๋Š” ์‚ฌ์ดํŠธ์— ๋ฐฉ๋ฌธํ•˜๊ธฐ ์œ„ํ•ด ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ž…๋ ฅํ•˜๋Š” ์ฃผ์†Œ๋ฅผ ๋งํ•ฉ๋‹ˆ๋‹ค. https ์ ์šฉ์— ์žˆ์–ด์„œ ๋„๋ฉ”์ธ์ด ํ•„์š”ํ•œ ์ด์œ ๋Š” SSL ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰๋ฐ›์„ ๋•Œ ๋„๋ฉ”์ธ์ด ์•„๋‹ˆ๋ผ IP์ผ ๊ฒฝ์šฐ์—๋Š” ์ธ์ฆ์„œ ๋ฐœ๊ธ‰์ด ์ œํ•œ๋˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.
๋„๋ฉ”์ธ์„ ์–ป์„ ์ˆ˜ ์žˆ๋Š” ์‚ฌ์ดํŠธ๋Š” ๊ต‰์žฅํžˆ ๋งŽ์ง€๋งŒ ์ €๋Š” ๊ทธ์ค‘ ๊ฐ€๋น„์•„๋ผ๋Š” ์‚ฌ์ดํŠธ๋ฅผ ์ด์šฉํ•ด์„œ ๊ตฌ๋งคํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

์›น์„ ๋„˜์–ด ํด๋ผ์šฐ๋“œ๋กœ. ๊ฐ€๋น„์•„

๊ทธ๋ฃน์›จ์–ด๋ถ€ํ„ฐ ๋ฉ€ํ‹ฐํด๋ผ์šฐ๋“œ๊นŒ์ง€ ํ•˜๋‚˜์˜ ํด๋ผ์šฐ๋“œ ํ—ˆ๋ธŒ

www.gabia.com

์›ํ•˜๋Š” ๋„๋ฉ”์ธ ๊ฒ€์ƒ‰

๊ฐ€๋น„์•„ ๋กœ๊ทธ์ธ ํ›„ ๊ฒ€์ƒ‰์ฐฝ์— ์›ํ•˜๋Š” ๋„๋ฉ”์ธ์„ ์ž…๋ ฅํ•œ ๋’ค ๊ฒ€์ƒ‰์„ ๋ˆ„๋ฆ…๋‹ˆ๋‹ค.

์›ํ•˜๋Š” ๋„๋ฉ”์ธ ์„ ํƒ

๊ฐ€๊ฒฉ์„ ๋ณด์‹œ๊ณ  ์›ํ•˜๋Š” ๋„๋ฉ”์ธ์„ ์„ ํƒ ํ›„ ๊ตฌ๋งค๊ณผ์ •์„ ์ง„ํ–‰ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์—ฐ์Šต์šฉ์ด๋ฉด 500์›์ด๋‚˜ 1900์›์งœ๋ฆฌ๋ฅผ ๊ตฌ๋งคํ•˜๋Š” ๊ฒŒ ๋ฒ ์ŠคํŠธ์ž…๋‹ˆ๋‹ค.

๋“ฑ๋ก ๊ธฐ๊ฐ„ ํ™•์ธ

๋“ฑ๋ก ๊ธฐ๊ฐ„์ด ๋””ํดํŠธ๋กœ 3๋…„์ด ์žกํ˜€์žˆ๋Š”๋ฐ ํ•„ํžˆ 1๋…„์œผ๋กœ ์ง€์ •ํ•ด์ฃผ์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. 1๋…„๋งŒ ํ• ์ธ๊ฐ€๊ฒฉ์ด ์ ์šฉ๋˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค. ์ด ์™ธ์—๋Š” ๋”ฐ๋กœ ๊ฑด๋“œ๋ฆฌ์ง€ ์•Š๊ณ  ๊ตฌ๋งค๋งŒ ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

My๊ฐ€๋น„์•„ -> ์„œ๋น„์Šค ๊ด€๋ฆฌ

๊ตฌ๋งค ํ›„ 'My๊ฐ€๋น„์•„ -> ์„œ๋น„์Šค ๊ด€๋ฆฌ'์— ๊ฐ€์‹œ๋ฉด ์œ„์™€ ๊ฐ™์ด ๋ณธ์ธ์ด ๋ฐฉ๊ธˆ ๊ตฌ๋งคํ•œ ๋„๋ฉ”์ธ์ด ๊ตฌ๋งค ํ›„๋กœ๋ถ€ํ„ฐ 5๋ถ„ ๋‚ด์™ธ๋กœ ๋‚˜ํƒ€๋‚ฉ๋‹ˆ๋‹ค.

๊ด€๋ฆฌ -> DNS ์ •๋ณด -> DNS ๊ด€๋ฆฌ ํด๋ฆญ
๋ณธ์ธ์˜ ๋„๋ฉ”์ธ ์„ค์ • ํด๋ฆญ

๊ทธ ํ›„ '๊ด€๋ฆฌ -> DNS ์ •๋ณด -> DNS ๊ด€๋ฆฌ'์— ๋“ค์–ด๊ฐ€์‹œ๋ฉด ์œ„์™€ ๊ฐ™์€ ๊ด€๋ฆฌ ํŽ˜์ด์ง€๋กœ ๋„˜์–ด๊ฐ€๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

DNS ๋ ˆ์ฝ”๋“œ ์ž…๋ ฅ

'์„ค์ • -> ๋ ˆ์ฝ”๋“œ ์ˆ˜์ •'์„ ๋ˆŒ๋Ÿฌ์„œ DNS ๋ ˆ์ฝ”๋“œ ์ˆ˜์ •์„ ๋„์šด ๋’ค ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์–‘์‹์œผ๋กœ ์ž…๋ ฅํ•˜๊ณ  ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.
๊ฐ’/์œ„์น˜ ๋ถ€๋ถ„์— ๋ณธ์ธ์˜ ์„œ๋ฒ„ ์•„์ดํ”ผ๋ฅผ ์ž…๋ ฅํ•˜๊ณ , ํ˜ธ์ŠคํŠธ๋Š” www์™€ @ ๋‘ ๊ฐœ๋ฅผ ์ง€์ •ํ•˜๋Š”๋ฐ, ์ด๋Š” ๋„๋ฉ”์ธ์— www๋ฅผ ๋ถ™์˜€์„ ๋•Œ์™€ ๋ถ™์ด์ง€ ์•Š์•˜์„ ๋•Œ ๋ชจ๋‘ ๋‹ค ์ ์šฉ๋˜๋„๋ก ํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

๋„๋ฉ”์ธ ์ ์šฉ์ด ๋œ ๋ชจ์Šต

์ €์žฅ ํ›„ 5๋ถ„ ๋‚ด์™ธ๋กœ ๋ณธ์ธ์˜ ์„œ๋ฒ„ ์•„์ดํ”ผ ๋Œ€์‹ ์— ๋„๋ฉ”์ธ์œผ๋กœ ์ ‘์†ํ•˜๋ฉด ์ž‘๋™์ด ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

2. Nginx ์„ค์น˜ ๋ฐ ์ˆ˜์ •

๋จผ์ € ์ €๋Š” Amazone Linux ํ™˜๊ฒฝ์—์„œ ์ž‘์—…์„ ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค. Ubuntu๋‚˜ ์ผ๋ฐ˜ Linux๋กœ ์ž‘์—…ํ•˜์‹œ๋Š” ๋ถ„์€ ์„ค์น˜๋ฐฉ๋ฒ•์ด ๋‹ค๋ฅด๋‹ˆ ์œ ์˜ํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค. ์ ์šฉ ๊ณผ์ •์€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค.

sudo amazon-linux-extras install -y nginx1

2-1) Nginx ์„ค์น˜

๋จผ์ € Amazone Linux์—์„œ๋Š” yum์„ ํ†ตํ•œ nginx ์„ค์น˜๋ฅผ ์ง€์›ํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์œ„์™€ ๊ฐ™์€ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด Nginx๋ฅผ ์„ค์น˜ํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ •์ƒ์ ์œผ๋กœ ์„ค์น˜๋˜์—ˆ๋Š”์ง€ ํ™•์ธ
nginx -v

์ •์ƒ์ ์œผ๋กœ ์„ค์น˜๊ฐ€ ๋˜์—ˆ๋Š”์ง€๋Š” ์œ„ ๋ฒ„์ „ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

2-2) Nginx ์ˆ˜์ •

์ด์ œ Nginx์— ์šฐ๋ฆฌ๊ฐ€ 1๋ฒˆ์—์„œ ๊ตฌ๋งคํ•œ ๋„๋ฉ”์ธ์„ ์ž‘์„ฑํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. Nginx์˜ ์„ค์ • ํŒŒ์ผ๋“ค์€ ๋ณดํ†ต /etc/nginx/* ์•„๋ž˜์— ์œ„์น˜ํ•˜๊ณ  ์žˆ์œผ๋ฉฐ, ๋กœ๊ทธํŒŒ์ผ์€ /var/log/nginx/*์— ์œ„์น˜ํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

find / -name nginx.conf

๋งŒ์•ฝ ์„ค์ • ํŒŒ์ผ๋“ค์„ ์ฐพ์ง€ ๋ชปํ•  ๊ฒฝ์šฐ ์œ„์™€ ๊ฐ™์€ ๋ช…๋ น์–ด๋กœ ํ™˜๊ฒฝ ํŒŒ์ผ๋“ค์„ ์ฐพ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

sudo vi /etc/nginx/nginx.conf

์ €ํฌ๊ฐ€ ์ˆ˜์ •ํ•  ํŒŒ์ผ์€ nginx.conf ํŒŒ์ผ์ž…๋‹ˆ๋‹ค. ์œ„ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์—ด์–ด์ค๋‹ˆ๋‹ค.

์ˆ˜์ •ํ•  ๋ถ€๋ถ„

nginx.conf ํŒŒ์ผ์—์„œ ์ˆ˜์ •ํ•  ๋ถ€๋ถ„์€ ์œ„ ์ด๋ฏธ์ง€์˜ ๋นจ๊ฐ„ ๋ฐ•์Šค ๋ถ€๋ถ„์ธ server_name์ž…๋‹ˆ๋‹ค. ๋ณธ์ธ์˜ ๋„๋ฉ”์ธ์„ ์ž…๋ ฅํ•˜๋ฉด ๋˜๋Š”๋ฐ server_name ๋„๋ฉ”์ธ www.๋„๋ฉ”์ธ; ๊ณผ ๊ฐ™์€ ํ˜•์‹์œผ๋กœ ์ž…๋ ฅํ•ฉ๋‹ˆ๋‹ค.

์ˆ˜์ •ํ•œ ๋ชจ์Šต

3. Cerbot ์„ค์น˜ ๋ฐ SSL ๋ฐœ๊ธ‰

sudo wget -r --no-parent -A 'epel-release-*.rpm' http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/

sudo rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-*.rpm

sudo yum-config-manager --enable epel*

sudo yum install -y certbot python2-certbot-apache

sudo yum install certbot-nginx

์œ„ ๋ช…๋ น์–ด๋ฅผ ์ˆœ์ฐจ์ ์œผ๋กœ ์‹คํ–‰ํ•˜์—ฌ Certbot์„ ์„ค์น˜ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

sudo certbot --nginx

Cerbot์ด ์„ค์น˜๋˜์—ˆ๋‹ค๋ฉด ์œ„ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰๋ฐ›๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

2๋ฒˆ์—์„œ server_name์„ ๋ช…์‹œํ–ˆ์„ ๊ฒฝ์šฐ

2๋ฒˆ์—์„œ Nginx ์„ค์ • ํŒŒ์ผ์— server_name์„ ๋ช…์‹œํ–ˆ์„ ๊ฒฝ์šฐ ์œ„ ์ด๋ฏธ์ง€์™€ ๊ฐ™์ด ๋„๋ฉ”์ธ(server_name)์ด ์ž๋™์œผ๋กœ ๋งค์นญ์ด ๋˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ํ™•์ธ์ด ๋˜์—ˆ๋‹ค๋ฉด ์—”ํ„ฐ๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ์ง„ํ–‰ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.
๋งŒ์•ฝ Nginx ์„ค์ • ํŒŒ์ผ์—์„œ server_name์„ ์ง€์ •ํ•ด์ฃผ์ง€ ์•Š์•˜์„ ๊ฒฝ์šฐ dkswnkk.shop www.dkswnkk.shop์™€ ๊ฐ™์€ ์–‘์‹์œผ๋กœ ์ž…๋ ฅํ•˜์—ฌ ์ง์ ‘ ์ง€์ •ํ•ด์ฃผ๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. (ex: dkswnkk.shop www.dkswnkk.shop)

์ด๋ฉ”์ผ ์ž…๋ ฅ

๊ณ„์†ํ•ด์„œ ์ˆ˜ํ–‰ํ•˜๋ฉด ๋จผ์ € ์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•˜๋ผ๊ณ  ๋‚˜์˜ต๋‹ˆ๋‹ค. ๋ณธ์ธ์˜ ์ด๋ฉ”์ผ์„ ์ž…๋ ฅํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

ACME ์„œ๋ฒ„์— ๋“ฑ๋กํ•  ๊ฒƒ์ธ์ง€ ๋™์˜ ์—ฌ๋ถ€

๊ทธ๋‹ค์Œ Y๋ฅผ ์ž…๋ ฅํ•˜์—ฌ ๋™์˜ํ•ด์ค๋‹ˆ๋‹ค.

EFF ์†Œ์‹์„ ์ด๋ฉ”์ผ๋กœ ๋ฐ›์„์ง€ ์„ ํƒ

์ด๋ฉ”์ผ ์ˆ˜์‹  ์—ฌ๋ถ€๋Š” ์ž์œ ๋กญ๊ฒŒ ์ž…๋ ฅํ•˜์—ฌ ๋‹ค์Œ์œผ๋กœ ๋„˜์–ด๊ฐ€ ์ค๋‹ˆ๋‹ค.

์ธ์ฆ์„œ ๋ฐœ๊ธ‰ ์„ฑ๊ณต!

๊ทธ๋Ÿผ ์„ฑ๊ณต์ ์œผ๋กœ ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰๋ฐ›์€ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์—ฌ๊ธฐ์„œ ๋งŒ์•ฝ ์ˆซ์ž 1๊ณผ 2๋ฅผ ์„ ํƒํ•˜๋ผ๋Š” ๋ฌธ์žฅ์ด ๋‚˜์˜จ๋‹ค๋ฉด ํ•ด๋‹น ๋ฌธ์žฅ์€ ๊ธฐ์กด http ์—ฐ๊ฒฐ์„ ์–ด๋–ป๊ฒŒ ์„ค์ •ํ•  ๊ฒƒ์ธ๊ฐ€์— ๋Œ€ํ•œ ์งˆ๋ฌธ์ž…๋‹ˆ๋‹ค.

  • 1์„ ์ž…๋ ฅํ•œ๋‹ค๋ฉด http ์—ฐ๊ฒฐ์„ https๋กœ ์ž๋™์œผ๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ํ•˜์ง€ ์•Š๋Š”๋‹ค.
  • 2๋ฅผ ์ž…๋ ฅํ•œ๋‹ค๋ฉด http ์—ฐ๊ฒฐ์„ https๋กœ ์ž๋™์œผ๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ํ•œ๋‹ค.

1 ๋˜๋Š” 2๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ์—”ํ„ฐ๋ฅผ ๋ˆ„๋ฅด๋ฉด, ๊ตฌ์„ฑ์ด ์—…๋ฐ์ดํŠธ๋˜๊ณ  Nginx๊ฐ€ ์žฌ์‹œ์ž‘๋ฉ๋‹ˆ๋‹ค. ์ดํ›„ ์ž๋™์œผ๋กœ ๋“ฑ๋ก๋˜๋ฉฐ, 3๊ฐœ์›” ๋’ค์— ์ž๋™์œผ๋กœ ๊ฐฑ์‹ ๋˜๋Š” ์Šค์ผ€์ค„๋„ ๋“ฑ๋ก๋ฉ๋‹ˆ๋‹ค.

4. Proxy ์„ค์ •

์ด์ œ ์šฐ๋ฆฌ๊ฐ€ ๊ตฌ๋งคํ•œ ๋„๋ฉ”์ธ์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ์ฃผ์†Œ๋กœ ์ ‘๊ทผํ•˜๋ฉด ์šฐ๋ฆฌ์˜ ์Šคํ”„๋ง ์„œ๋ฒ„๋กœ ์—ฐ๊ฒฐ์„ ๋ณด๋‚ด๊ธฐ ์œ„ํ•ด proxy_pass ์„ค์ •์„ ํ•ด์ค˜์•ผ ํ•ฉ๋‹ˆ๋‹ค.

sudo vi /etc/nginx/nginx.conf

๋‹ค์‹œ ์œ„์˜ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด Nginx ์„ค์ • ํŒŒ์ผ์„ ์—ฐ ๋’ค ์•„๋ž˜์™€ ๊ฐ™์ด ์ž…๋ ฅ ํ›„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

์ž…๋ ฅํ•  ๋ถ€๋ถ„
location / {
               proxy_pass http://localhost:8080; # ์ž์‹ ์˜ springboot app์ด์‚ฌ์šฉํ•˜๋Š” ํฌํŠธ
               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;
           }
์ž…๋ ฅ ํ•œ ๋ชจ์Šต

์ด๋ฏธ์ง€์˜ ํ™”์‚ดํ‘œ ๋ถ€๋ถ„์— ์œ„์™€ ๊ฐ™์€ ์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ์ €์žฅํ•ฉ๋‹ˆ๋‹ค.

 sudo service nginx restart

์ด์ œ ์œ„ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด Nginx๋ฅผ ์žฌ ์‹คํ–‰ ํ›„ https://๋ณธ์ธ์˜ ๋„๋ฉ”์ธ์— ์ ‘์†ํ•˜๊ฒŒ ๋˜๋ฉด https๊ฐ€ ์„ฑ๊ณต์ ์œผ๋กœ ์ ์šฉ์ด ๋œ ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์„ฑ๊ณต์ ์œผ๋กœ https ์ ์šฉ ๋œ ๋ชจ์Šต

๋˜ํ•œ http๋กœ ์ ‘์†ํ•ด๋„ ์ž๋™์œผ๋กœ https๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ๋˜๋Š” ๊ฒƒ๋„ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์—ฌ๊ธฐ์„œ ํ˜น์‹œ ์ ‘์†์ด ๋˜์ง€ ์•Š์œผ์‹œ๋Š” ๋ถ„๋“ค์€ ์„œ๋ฒ„ EC2์˜ ๋ณด์•ˆ ๊ทธ๋ฃน ์ค‘ ์ธ๋ฐ”์šด๋“œ์—์„œ 443 ํฌํŠธ๊ฐ€ ์—ด๋ ค์žˆ๋Š”์ง€ ํ™•์ธํ•˜์‹œ๊ธฐ ๋ฐ”๋ž๋‹ˆ๋‹ค.

5. ์ธ์ฆ์„œ ์ž๋™ ๊ฐฑ์‹ (์„ ํƒ)

Cerbot์€ ๋ฌด๋ฃŒ๋กœ ์ œ๊ณตํ•˜๋‹ค ๋ณด๋‹ˆ ๊ธฐ๋ณธ์ ์œผ๋กœ 90์ผ์˜ ๋งŒ๋ฃŒ๊ธฐ๊ฐ„์ด ์žˆ์Šต๋‹ˆ๋‹ค. ํ•˜์ง€๋งŒ 90์ผ๋งˆ๋‹ค ๋งค๋ฒˆ ์„œ๋ฒ„์— ์ ‘์†ํ•˜์—ฌ ์ƒˆ๋กœ์šด ์ธ์ฆ์„œ๋ฅผ ๋ฐœ๊ธ‰ํ•˜๋Š” ๊ฒƒ์€ ๋ฒˆ๊ฑฐ๋กœ์›€์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์ด๋ฅผ cron์„ ํ†ตํ•ด ์ž๋™ํ™”ํ•˜์—ฌ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

sudo vi /etc/crontab

๋จผ์ € crontab ํŒŒ์ผ์„ ์ˆ˜์ •ํ•˜์—ฌ cron์„ ์ง€์ •ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค. ์œ„ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด crontab์„ ์—ฝ๋‹ˆ๋‹ค.

39 1,13 * * * root certbot renew --no-self-upgrade

์œ„ ๋‚ด์šฉ์„ ์ž…๋ ฅ ํ›„ ์ €์žฅํ•ฉ๋‹ˆ๋‹ค. ์œ„์˜ ๋ช…๋ น์€ ๋‹ค์Œ๊ณผ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • 39 1,13 * * * : ๋งค์ผ 1์‹œ 39๋ถ„, 13์‹œ 39๋ถ„์— ์‹คํ–‰ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.
  • root : ๋ช…๋ น์ด root ๊ถŒํ•œ์œผ๋กœ ์‹คํ–‰ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.
  • certbot renew --no-self-upgrade : Let's Encrypt ์ธ์ฆ์„œ๋ฅผ ๊ฐฑ์‹ ํ•ฉ๋‹ˆ๋‹ค.
    renew๋Š” Certbot์ด ์ด์ „์— ์–ป์€ ๋ชจ๋“  ์ธ์ฆ์„œ๊ฐ€ ์ ๊ฒ€ํ•˜๊ณ  ๋งŒ๋ฃŒ ๋‚ ์งœ๊ฐ€ ๋‹ค๊ฐ€์˜ค๊ณ  ์žˆ๋Š” ์ธ์ฆ์„œ๋ฅผ ๊ฐฑ์‹ ํ•ฉ๋‹ˆ๋‹ค.
    --no-self-upgrade ํ”Œ๋ž˜๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด Certbot์ด ์‚ฌ์šฉ์ž์˜ ๊ฐœ์ž… ์—†์ด ์ž์ฒด ์—…๊ทธ๋ ˆ์ด๋“œํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.
  1. ์‹œ๊ฐ„ ์„ค์ •์€ ์ž„์˜๋กœ ์ž‘์„ฑํ•œ ๊ฒƒ์ด์ง€๋งŒ, Certbot ๊ฐœ๋ฐœ์ž๋Š” ์ตœ์†Œํ•œ ๋งค์ผ ๋‘ ๋ฒˆ ๋ช…๋ น์„ ์‹คํ–‰ํ•˜๋Š” ๊ฒƒ์„ ์ œ์•ˆํ•œ๋‹ค๊ณ  ํ•ฉ๋‹ˆ๋‹ค.
  2. ์‹œ๊ฐ„ ์„ค์ •์€ 90์ผ์— ์•ˆ์ชฝ์œผ๋กœ ์›ํ•˜์‹œ๋Š” ๋‚ ์งœ์— ๋งž์ถฐ์„œ ์ž‘์„ฑํ•˜์…”๋„ ๋˜๊ฒ ์Šต๋‹ˆ๋‹ค.
  3. ๋ชจ๋“  ์„ค์ •์ด ๋๋‚ฌ๋‹ค๋ฉด cron์„ ์žฌ์‹คํ–‰ํ•˜์—ฌ ์ ์šฉ์‹œํ‚ค๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.
sudo systemctl restart crond

์ด์ œ crond๋ฅผ ์žฌ ์‹œ์ž‘ํ•˜์—ฌ ์ธ์ฆ์„œ๋ฅผ ์ž๋™์œผ๋กœ ๊ฐฑ์‹ ํ•˜๋„๋ก ํ•ฉ๋‹ˆ๋‹ค.

์ฐธ๊ณ 

Amazon Linux2์—์„œ Certbot์„ ํ†ตํ•ด HTTPS ์ ์šฉํ•˜๊ธฐ (With. Nginx)

AWS ํ”„๋ฆฌํ‹ฐ์–ด ์ค‘ Amazon Linux2๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์„œ๋ฒ„์—์„œ HTTPS๋ฅผ ์„œ๋น„์Šค์— ๋“ฑ๋กํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. HTTPS๊ฐ€ ์—†๋”๋ผ๋„ ํฌ๊ฒŒ ๋ฌธ์ œ๋Š” ์—†์ง€๋งŒ, ๋งŽ์€ ํšŒ์‚ฌ๋“ค์ด SSL์„ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์—, ์ ์šฉํ•ด๋ณด๊ณ ์ž ํ•˜์˜€์Šต๋‹ˆ๋‹ค.

dev-jwblog.tistory.com