DevLog ๐Ÿ˜ถ

[Infra] AWS ๋ฐฐํฌ ํ›„ ๋„๋ฉ”์ธ ์—ฐ๊ฒฐ ๋ฐ HTTPS ์ ์šฉ, nginx๋กœ ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ ์ ์šฉํ•˜๊ธฐ ๋ณธ๋ฌธ

๊ฐœ๋ฐœ์ผ์ง€

[Infra] AWS ๋ฐฐํฌ ํ›„ ๋„๋ฉ”์ธ ์—ฐ๊ฒฐ ๋ฐ HTTPS ์ ์šฉ, nginx๋กœ ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ ์ ์šฉํ•˜๊ธฐ

dolmeng2 2023. 5. 28. 17:56

๐ŸŒฑ ๋“ค์–ด๊ฐ€๊ธฐ ์ „

๋ฌด๊ณผ๊ธˆ์œผ๋กœ HTTPS ์ ์šฉ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•ด๋ณด์•˜๋‹ค.

์ •์„๋Œ€๋กœ๋ผ๋ฉด ๊ฐ€๋น„์•„ + Route53 + ACM or ๊ฐ€๋น„์•„ + nginx๋กœ๋งŒ ์ง„ํ–‰ํ•˜๋ฉด ์ข‹์•˜๊ฒ ์ง€๋งŒ...

์—ฌ๋Ÿฌ ์ œ์•ฝ์‚ฌํ•ญ์œผ๋กœ ์ธํ•ด์„œ ์ƒ‰๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ ๋„๋ฉ”์ธ ์—ฐ๊ฒฐ ๋ฐ HTTPS ์ ์šฉ์„ ์ง„ํ–‰ํ•ด๋ณด์•˜๋‹ค.

 

๐Ÿ’ก ์ œ์•ฝ์‚ฌํ•ญ
- ๋ฌด๋ฃŒ ๋„๋ฉ”์ธ ์‚ฌ์šฉํ•˜๊ธฐ
- ์„œ๋ฒ„ 1๋Œ€๋กœ ๊ตฌ์ถ•ํ•˜๊ธฐ (๋Š์ž„์—†์ด ๊ณ ํ†ต๋ฐ›๋Š” t4g.micro)
- http ์ ‘์† ์‹œ https๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ์‹œํ‚ค๊ธฐ

 

๋‚˜์ค‘์— Route53 + ACM + ELB๋ฅผ ํ†ตํ•ด ๋„์ž…ํ–ˆ๋˜ ๊ฒƒ๋„ ํฌ์ŠคํŒ…์œผ๋กœ ์ž‘์„ฑํ•ด๋ณด๊ณ ์ž ํ•œ๋‹ค. (์ด๋ฒˆ ๋ฏธ์…˜์—์„œ๋Š” ๋ชป ํ–ˆ์ง€๋งŒ ใ… )

 


 

๐ŸŒฑ ๋„๋ฉ”์ธ ๊ตฌ์ž…ํ•˜๊ธฐ

์‚ฌ์‹ค ๊ฐ€๋น„์•„์—์„œ ๊ตฌ๋งคํ–ˆ๋˜ ๋„๋ฉ”์ธ์ด ์žˆ๊ธด ํ•˜์ง€๋งŒ, ํŽ˜์–ด ํ”„๋กœ๊ทธ๋ž˜๋ฐ์„ ํ•˜๋‹ค ๋ณด๋‹ˆ ๋‚˜๋งŒ์˜ ๋„๋ฉ”์ธ์„ ์‚ฌ์šฉํ•˜๊ธฐ๋Š” ์ข€ ๊ทธ๋ž˜์„œ ๋‹ค๋ฅธ ์‚ฌ์ดํŠธ๋ฅผ ์ฐพ์•„๋ณด์•˜๋‹ค. ๊ทธ๋Ÿฌ๋‹ค๊ฐ€ ๋ฐœ๊ฒฌํ•œ ๊ณณ = ๋‚ด๋„๋ฉ”์ธ.ํ•œ๊ตญ!

 

๋‚ด๋„๋ฉ”์ธ.ํ•œ๊ตญ - ํ•œ๊ธ€ ๋ฌด๋ฃŒ ๋„๋ฉ”์ธ ๋“ฑ๋ก์„ผํ„ฐ

ํ•œ๊ธ€ ๋ฌด๋ฃŒ ๋„๋ฉ”์ธ ๋‚ด๋„๋ฉ”์ธ.ํ•œ๊ตญ, ์›นํฌ์›Œ๋”ฉ, DNS ๋“ฑ ๋ฌด๋ฃŒ ๋„๋ฉ”์ธ ๊ธฐ๋Šฅ ์ œ๊ณต

xn--220b31d95hq8o.xn--3e0b707e

๊ต‰์žฅํžˆ ์ˆ˜์ƒํ•˜๊ฒŒ ์ƒ๊ฒผ์ง€๋งŒ ์†๋„๋„ ๋น ๋ฅด๊ณ , ์ ์šฉํ•˜๋Š” ๋ฐ์—๋Š” ํฌ๊ฒŒ ๋ฌด๋ฆฌ๊ฐ€ ์—†์–ด์„œ ์—ฌ๊ธฐ์„œ ๊ตฌ์ž…ํ•˜๊ธฐ๋กœ ๊ฒฐ์ •ํ•˜์˜€๋‹ค.

 

๋จผ์ € ์ผ๋ฐ˜ ๋„๋ฉ”์ธ ๊ฒ€์ƒ‰์ฐฝ์— ๋“ฑ๋กํ•˜๊ณ  ์‹ถ์€ ๋„๋ฉ”์ธ์„ ๊ฒ€์ƒ‰ํ•œ๋‹ค.

5๋ฒˆ์€ ํ˜„์žฌ ๋‚ด๊ฐ€ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋“ฑ๋ก ๋ถˆ๊ฐ€๋กœ ๋œฌ๋‹ค ใ…Žใ…Ž

์ฒ˜์Œ์— ๊ตฌ์ž…ํ•˜๋ฉด ์œ„์™€ ๊ฐ™์ด DNS ์—ฐ๊ฒฐ์„ ํ•  ์ˆ˜ ์žˆ๋Š”๋ฐ, ์šฐ์„  A ๋ ˆ์ฝ”๋“œ์— AWS ์ธ์Šคํ„ด์Šค์˜ public IP๋ฅผ ์ž‘์„ฑํ•œ๋‹ค.

์—ฌ๊ธฐ์„œ A ๋ ˆ์ฝ”๋“œ๋ฅผ ๋“ฑ๋กํ•œ๋‹ค๋Š” ์˜๋ฏธ๋Š”, DNS ์„œ๋ฒ„์— ์šฐ๋ฆฌ๊ฐ€ ๊ตฌ๋งคํ•œ ๋„๋ฉ”์ธ๊ณผ IP๋ฅผ ์—ฐ๊ฒฐํ•œ๋‹ค๋Š” ์˜๋ฏธ์ธ๋ฐ,

journey-shop.kro.kr๋กœ ๋ธŒ๋ผ์šฐ์ €์—์„œ ์ ‘์†ํ•˜๋ฉด 12.34.56.78 (IP)๋กœ ์ ‘์†ํ•  ์ˆ˜ ์žˆ๋„๋ก ๋งŒ๋“ ๋‹ค๋Š” ๋œป์ด๋‹ค.

CNAME์€ ์ถ”ํ›„ ์„ค์ •ํ•  ์˜ˆ์ •์ด์ง€๋งŒ, ํ•ด๋‹น ๋„๋ฉ”์ธ์— ๋Œ€ํ•œ ๋ณ„์นญ์„ ์ง€์ •ํ•œ๋‹ค๋Š” ์˜๋ฏธ ์ •๋„๋กœ ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค.

 

๋“ฑ๋กํ•˜๊ณ  journey-shop.kro.kr:8080/admin์œผ๋กœ ์ ‘์†ํ•˜๊ฒŒ ๋˜๋ฉด ์œ„์™€ ๊ฐ™์ด ๋ฉ‹์ง„ ์ฐฝ์ด ๋œจ๊ฒŒ ๋œ๋‹ค.

๋” ์ด์ƒ IP ์ฃผ์†Œ๋กœ ์ ‘๊ทผํ•˜์ง€ ์•Š๊ณ , ์‚ฌ๋žŒ์—๊ฒŒ ์ต์ˆ™ํ•œ ๋„๋ฉ”์ธ๋ช…์œผ๋กœ ์‚ฌ์ดํŠธ์— ์ ‘์†์ด ๊ฐ€๋Šฅํ•œ ๊ฒƒ์ด๋‹ค.

 


 

๐ŸŒฑ HTTPS ์—ฐ๋™ํ•˜๊ธฐ

ํ•˜์ง€๋งŒ, ์œ„์—์„œ ์ง„ํ–‰ํ•œ ๊ณผ์ •์€ IP ๋Œ€์‹ ์— ๋‹จ์ˆœํžˆ ๋„๋ฉ”์ธ๋ช…์„ ์‚ฌ์šฉํ–ˆ์„ ๋ฟ์ด๋‹ค. 

์šฐ๋ฆฌ๊ฐ€ ๋„ค์ด๋ฒ„์— ์ ‘์†ํ•  ๋•Œ naver.com:8080๊ณผ ๊ฐ™์ด ์ ‘์†ํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์ฒ˜๋Ÿผ, ํฌํŠธ ๋ฒˆํ˜ธ ์—†์ด, https ํ™˜๊ฒฝ์œผ๋กœ ์ ‘์†ํ•˜๊ณ  ์‹ถ์„ ๊ฒƒ์ด๋‹ค.

(๋˜ํ•œ, ํ”„๋ก ํŠธ์—”๋“œ ์„œ๋ฒ„๊ฐ€ ๋ฐฐํฌ ์„œ๋ฒ„๋ผ๋ฉด https -> http๋Š” CORS์— ์˜ํ•ด์„œ ํ†ต์‹ ์ด ๋ถˆ๊ฐ€๋Šฅํ•˜๋‹ค ๐Ÿฅฒ)

๊ทธ๋ž˜์„œ ์ด๋ฒˆ์—๋Š” ๊ฐ„๋‹จํ•˜๊ฒŒ https๋ฅผ ์ ์šฉํ•ด๋ณด๊ณ ์ž ํ•œ๋‹ค.

 

https๋Š” ์•”ํ˜ธํ™”๋œ ํ”„๋กœํ† ์ฝœ์ด๋‹ค. ๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ์‹ ๋ขฐ๋œ ๊ธฐ๊ด€์ด ์ œ๊ณตํ•ด์ฃผ๋Š” ์ธ์ฆ์„œ๊ฐ€ ํ•„์š”ํ•˜๋‹ค.

์ฒ˜์Œ์—๋Š” certbot์„ ์‚ฌ์šฉํ•˜๋ ค๊ณ  ํ–ˆ์œผ๋‚˜... ๋ฌด๋ฃŒ ๋„๋ฉ”์ธ์„ ์‚ฌ์šฉํ•˜๋‹ค ๋ณด๋‹ˆ kro.kr๋กœ ์š”์ฒญ์ด ๋„ˆ๋ฌด ๋งŽ์ด ๋“ค์–ด์™€์„œ ๋‹น์žฅ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์—†๋‹ค๋Š” ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๊ณ  ๋ง์•˜๋‹ค.

too many certificates already issued for "kro.kr"

๊ทธ๋ž˜์„œ 1์‹œ๊ฐ„ ์ •๋„ ์ฒ˜์Œ์—๋Š” ๊ธฐ๋‹ค๋ฆฌ๋ ค๊ณ  ํ–ˆ์ง€๋งŒ, ๋ฐ”๋กœ ์ง„ํ–‰ํ•˜๊ณ  ์‹ถ์–ด์„œ ๊ฒฐ๊ตญ ํฌ๊ธฐ...

 

ํ˜น์‹œ ํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ์ง„ํ–‰ํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

sudo apt update

# certbot ์„ค์น˜
sudo apt install certbot

# www์˜ ๊ฒฝ์šฐ ์„ ํƒ์‚ฌํ•ญ
sudo certbot certonly --standalone -d journey-shop.kro.kr -d www.journey-shop.kro.kr

# ์ธ์ฆ์„œ ํŒŒ์ผ ํ™•์ธ
sudo ls /etc/letsencrypt/live/journey-shop.kro.kr/
cert.pem  chain.pem  fullchain.pem  privkey.pem

 

์•„๋ฌดํŠผ, ์–ด๋–ค ๋ฐฉ๋ฒ•์„ ์‚ฌ์šฉํ• ์ง€ ๊ณ ๋ฏผํ•˜๋‹ค๊ฐ€ SSL for Free์ด๋ผ๋Š” ์‚ฌ์ดํŠธ๋ฅผ ๋ฐœ๊ฒฌํ•˜์˜€๋‹ค.

 

SSL For Free - Free SSL Certificates in Minutes

Wildcard SSL Certificates Wildcard certificates allow you to secure any sub-domains under a domain. If you want to secure any sub-domains of example.org that you have now or in the future you can make a wildcard certificate. To generate wildcard certificat

www.sslforfree.com

๊ฐ€์ž…ํ•˜๊ณ  ๋‚˜์„œ Domain ์ž…๋ ฅํ•ด์ฃผ๊ณ , Validity์— 90์ผ, Auto-Generate CSR์„ ์ผœ์ฃผ๋ฉด ๋œ๋‹ค.

๊ทธ๋ฆฌ๊ณ , ์•…์˜์ ์ธ ์‚ฌ๋žŒ์ด ๋‚ด ๋„๋ฉ”์ธ์— ๋Œ€ํ•ด์„œ ๋ฉ‹๋Œ€๋กœ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— journey.kro.kr์ด ์ •๋ง SSL ๋ฐœ๊ธ‰์ž์˜ ์†Œ์œ  ๋„๋ฉ”์ธ์ธ์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด 3๊ฐ€์ง€์˜ ์ธ์ฆ ๋ฐฉ๋ฒ•์ด ์ฃผ์–ด์ง„๋‹ค. (๋ฉ”์ผ ์ธ์ฆ, DNS, HTTP File upload)

 

๋ฉ”์ผ ์ธ์ฆ์˜ ๊ฒฝ์šฐ ๋‚ด๋„๋ฉ”์ธ.ํ•œ๊ตญ์„ ์‚ฌ์šฉํ–ˆ๋‹ค ๋ณด๋‹ˆ kro.kr์˜ ์†Œ์œ ์ฃผ์˜ ์ด๋ฉ”์ผ๋กœ ์ „์†ก๋˜๊ธฐ ๋•Œ๋ฌธ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์—†์—ˆ๋‹ค.

File upload์˜ ๊ฒฝ์šฐ ์šฐ๋ฆฌ์˜ ์Šคํ”„๋ง ๋ถ€ํŠธ ์„œ๋ฒ„์— ssl for free์—์„œ ์ง€์ •ํ•ด์ค€ ๊ฒฝ๋กœ์— ํŒŒ์ผ์„ ์—…๋กœ๋“œ ํ›„ ๋ฐฐํฌํ•˜์—ฌ, ํ•ด๋‹น url๋กœ ์ด ์‚ฌ์ดํŠธ๊ฐ€ GET ์š”์ฒญ์„ ๋ณด๋‚ด health checking์„ ์ง„ํ–‰ํ•˜๋Š” ๋ฐฉ์‹์ธ๋ฐ, ํ”„๋กœ๋•์…˜ ์ฝ”๋“œ๊ฐ€ ๋”๋Ÿฝํ˜€์ง€๋Š” ๊ฒŒ ์‹ซ์–ด์„œ ํŒจ์Šคํ•˜์˜€๋‹ค.

๊ทธ๋ž˜์„œ ๋งˆ์ง€๋ง‰ ๋ฐฉ๋ฒ•์œผ๋กœ, ์ด ์‚ฌ์ดํŠธ์—์„œ ์ง€์ •ํ•œ CNAME์„ ์šฐ๋ฆฌ์˜ ๋„๋ฉ”์ธ์— ์—ฐ๊ฒฐํ•˜์—ฌ ์†Œ์œ ๊ถŒ์„ ๊ฒ€์ฆํ•˜๋Š” ๋ฐฉ๋ฒ•์„ ์ฑ„ํƒํ•˜์˜€๋‹ค.

์œ„์—์„œ ์ฃผ์–ด์ง„ NAME, Point to๋ฅผ ๊ฐ๊ฐ ์ž…๋ ฅํ•ด์ฃผ๋ฉด ๋œ๋‹ค.

 

๋‹ค ์ง„ํ–‰ํ–ˆ๋‹ค๋ฉด verify Domain์„ ํด๋ฆญํ•ด์ฃผ๊ณ , ์•„๋ž˜์™€ ๊ฐ™์ด ๋ฌธ์ œ ์—†๋‹ค๊ณ  ๋œฌ๋‹ค๋ฉด ์„ฑ๊ณต์ด๋‹ค.

๊ทธ๋ฆฌ๊ณ , Certificate ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์•„์•ผ ํ•˜๋Š”๋ฐ 'Ubuntu'์œผ๋กœ ์„ค์ •ํ•œ ๋‹ค์Œ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์•˜๋‹ค. 

 

๊ทธ๋Ÿฌ๋ฉด 3๊ฐ€์ง€์˜ ํŒŒ์ผ์„ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š”๋ฐ, ca_bundle.crt, certificate.crt, private.key๋ฅผ ์–ป๊ฒŒ ๋œ๋‹ค.

ca_bundle.crt (= chain.pem)
 : ์ธ์ฆ ์ฒด์ธ์ด๋‚˜ ์ค‘๊ฐ„ ์ธ์ฆ ๊ธฐ๊ด€์˜ ์ธ์ฆ์„œ๋“ค์„ ํฌํ•จํ•œ๋‹ค.
์ธ์ฆ ์ฒด์ธ์€ ์ธ์ฆ์„œ ๋ฐœ๊ธ‰ ๊ธฐ๊ด€์—์„œ ์ตœ์ƒ์œ„ ์ธ์ฆ ๊ธฐ๊ด€๊นŒ์ง€ ๊ณ„์ธต์  ๊ตฌ์กฐ๋กœ ๊ตฌ์„ฑ๋˜๋ฉฐ, ์„œ๋ฒ„ ์ธ์ฆ์„œ์™€ ํ•จ๊ป˜ ์ œ์ข…๋˜๋Š” CA์˜ ์ธ์ฆ์„œ ์ฒด์ธ์„ ์˜๋ฏธํ•œ๋‹ค. ๋ณดํ†ต ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ธ์ฆ์„œ๋ฅผ ๊ฒ€์ฆํ•  ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค.

certificate.crt (= fullchain.pem)
: ์„œ๋ฒ„์˜ SSL / TLS ์ธ์ฆ์„œ๋ฅผ ํฌํ•จํ•˜๋ฉฐ, ์›น ์„œ๋ฒ„์— ์„ค์น˜๋˜๋Š” ์ธ์ฆ์„œ์ด๋‹ค.
์„œ๋ฒ„์˜ ๊ณต๊ฐœํ‚ค์™€ ์„œ๋ฒ„ ์ •๋ณด๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๋‹ค.

private.key (= privkey.pem)
: ์„œ๋ฒ„์˜ ๊ฐœ์ธ ํ‚ค๋ฅผ ํฌํ•จํ•˜๋ฉฐ, ์„œ๋ฒ„ ์ธก์—์„œ ์ธ์ฆ์„œ์™€ ๋งค์นญ๋˜๋Š” ์ผ์ข…์˜ ๋น„๋ฐ€ ํ‚ค์ด๋‹ค.
SSL / TLS์˜ ์•”๋ณตํ˜ธํ™”์—์„œ ์‚ฌ์šฉ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์™ธ๋ถ€์— ๋…ธ์ถœ๋ผ์„œ๋Š” ์•ˆ ๋œ๋‹ค.

 

ํ•˜์ง€๋งŒ, ์ถ”ํ›„ nginx์—์„œ ์ธ์ฆ์„œ๋ฅผ ๋“ฑ๋กํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” crt ํŒŒ์ผ ํ˜•์‹์ด ์•„๋‹Œ pem ํ‚ค ํ˜•์‹์ด ํ•„์š”ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋ณ„๋„๋กœ ๋ณ€ํ™˜ํ•˜๋Š” ์ž‘์—…์ด ํ•„์š”ํ•˜๋‹ค.

openssl x509 -inform PEM -in certificate.crt > certificate.pem

 

๊ทธ๋ž˜์„œ, ์„œ๋ฒ„์˜ ์ธ์ฆ์„œ๋ฅผ openssl์„ ํ†ตํ•ด์„œ pem ํ˜•์‹์œผ๋กœ ๋ณ€ํ™˜ํ•ด์ฃผ์—ˆ๋‹ค.

 

๋งˆ์ง€๋ง‰์œผ๋กœ ์ธ์ฆ์„œ์™€ ํ‚ค๋ฅผ ๋‚ด ec2 ์ชฝ์œผ๋กœ ์˜ฎ๊ฒจ๋ณด์ž.

scp -i {EC2 ์ ‘์†์„ ์œ„ํ•œ ํ‚ค} certificate.pem ubuntu@{EC2 public IP}:{์ด๋™ํ•  path}
scp -i {EC2 ์ ‘์†์„ ์œ„ํ•œ ํ‚ค} private.key ubuntu@{EC2 public IP}:{์ด๋™ํ•  path}

์š”๋ ‡๊ฒŒ ํ•˜๋ฉด ์‚ฌ์ „ ์ค€๋น„๋Š” ์™„๋ฃŒ๋œ๋‹ค!

 


 

๐ŸŒฑ Nginx๋กœ ๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ ์ง„ํ–‰ํ•˜๊ธฐ

๋ฆฌ๋ฒ„์Šค ํ”„๋ก์‹œ๋Š” ์„œ๋ฒ„์˜ ์•ž๋‹จ์—์„œ ์‚ฌ์šฉ์ž์˜ ์š”์ฒญ์„ ๋ฐ›์•„ ์ ์ ˆํ•œ ์œ„์น˜๋กœ ํฌ์›Œ๋”ฉ์‹œํ‚ค๋Š” ๊ฒƒ์„ ๋งํ•œ๋‹ค.

์šฐ๋ฆฌ๋Š” ์—ฌ๊ธฐ์„œ 'nginx'๋ผ๋Š” ์นœ๊ตฌ๋ฅผ ์ด์šฉํ•ด์„œ http๋กœ ์˜จ ์š”์ฒญ์„ https๋กœ ๋ฐ”๊พธ๋Š” ์ž‘์—…์„ ์ง„ํ–‰ํ•ด๋ณด๊ณ ์ž ํ•œ๋‹ค ๐Ÿ˜Š

 

sudo apt install nginx

๋จผ์ €, nginx๋ฅผ ์„ค์น˜ํ•ด์ค€๋‹ค.

sudo ufw enable
sudo ufw status

๊ทธ๋ฆฌ๊ณ , ๋ฐฉํ™”๋ฒฝ์— ๋Œ€ํ•œ ์„ค์ •์„ ํ•ด์ค˜์•ผ ํ•˜๋Š”๋ฐ, ์šฐ๋ถ„ํˆฌ๋Š” ufw ๋ฐฉํ™”๋ฒฝ์„ ์‚ฌ์šฉํ•œ๋‹ค.

๊ธฐ๋ณธ์ ์œผ๋กœ ๋น„ํ™œ์„ฑํ™”๋˜์–ด ์žˆ๊ธฐ ๋•Œ๋ฌธ์— enable์„ ํ†ตํ•ด์„œ ํ™œ์„ฑํ™” ์‹œ์ผœ์ค€๋‹ค. ์ด๋Ÿฌ๋ฉด ๋ชจ๋“  ํฌํŠธ๊ฐ€ ์ž๋™์ ์œผ๋กœ ๋ง‰ํžˆ๊ฒŒ ๋œ๋‹ค.

status๋ฅผ ํ†ตํ•ด ํ˜„์žฌ ์–ด๋–ค ํฌํŠธ๊ฐ€ ์—ด๋ ค์žˆ๋Š”์ง€ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

์ค‘๊ฐ„์— ์บก์ณํ•œ ๊ฑฐ์—ฌ์„œ ๋ช‡๋ช‡์ด ์—ด๋ ค์žˆ๋‹ค.

 

sudo ufw allow ssh
sudo ufw allow 'Nginx Full'
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 8080/tcp

๋‚˜๋Š” ๋‹ค์Œ๊ณผ ๊ฐ™์ด ssh, nginx Full (์‚ฌ์‹ค ์ด๊ฒŒ 80์ด๋ž‘ 443 ์—ด์–ด์ฃผ๊ธด ํ•จ), 80, 443, 8080์„ ์—ด์–ด์ฃผ์—ˆ๋‹ค.

 

sudo systemctl start nginx
sudo systemctl status nginx

๊ทธ๋ฆฌ๊ณ , ์ž˜ ๊ฐ€๋™๋˜๋Š”์ง€ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด restart ํ›„ status๋ฅผ ํ™•์ธํ•œ๋‹ค.

์š”๋Ÿฐ ์‹์œผ๋กœ Active๊ฐ€ ๋–ด๋‹ค๋ฉด ์„ฑ๊ณต์ด๋‹ค.

๋‚˜์ค‘์—๋Š” restart ์˜ต์…˜์„ ๋งŽ์ด ์‚ฌ์šฉํ•  ํ…๋ฐ, status๋กœ ํ•ญ์ƒ ์ƒํƒœ๋ฅผ ํ•จ๊ป˜ ํ™•์ธํ•˜๋Š” ๊ฒƒ์„ ์ถ”์ฒœํ•œ๋‹ค.

 

๊ทธ๋ฆฌ๊ณ , ์ด์ œ ํฌ์›Œ๋”ฉ ์˜ต์…˜์„ ์ฃผ๊ธฐ ์œ„ํ•ด์„œ /etc/nginx/site-enabled๋กœ ์ด๋™ํ•œ๋‹ค.

๊ฑฐ๊ธฐ๋กœ ๊ฐ€๋ฉด 'default'๋ผ๋Š” ํŒŒ์ผ์ด ์žˆ์„ ํ…๋ฐ, ํ•ด๋‹น ํŒŒ์ผ์„ vi๋กœ ์ˆ˜์ •ํ•œ๋‹ค. 

cd /etc/nginx/site-enabled
sudo vi default
server {
	listen 80 default_server;
	listen [::]:80 default_server;

	listen 443 ssl default_server;
	listen [::]:443 ssl default_server;

	root /var/www/html;

	index index.html index.htm index.nginx-debian.html;

	server_name journey-shop.kro.kr;
	ssl_certificate /home/ubuntu/certificate.pem;
	ssl_certificate_key /home/ubuntu/private.key;
	ssl_prefer_server_ciphers on;

	location / {
          proxy_pass http://localhost:8080;
          proxy_set_header X-Real_IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $http_host;
	}
}


server {
  listen 80;
  server_name journey-shop.kro.kr;
  return 301 https://$host$request_uri;
}

๋ณด๊ธฐ๋งŒ ํ•ด๋„ ์–ด์ง€๋Ÿฝ๊ธฐ ๋•Œ๋ฌธ์— ํ•˜๋‚˜์”ฉ ์ชผ๊ฐœ์„œ ํ™•์ธํ•ด๋ณด์ž.

 


 

๐ŸŒฑ Nginx ์„ค์ • ํŒŒ์ผ ๋ถ„์„ํ•˜๊ธฐ

์—ฌ๊ธฐ์„œ default_server๋ผ๋Š” ์นœ๊ตฌ๋ฅผ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

nginx์—์„œ ์–ด๋–ค ํฌํŠธ๋กœ ์š”์ฒญ์ด ๋“ค์–ด์™”์„ ๋•Œ ์ง€์ •ํ•œ server ๋ธ”๋ก์„ ๊ธฐ๋ณธ์œผ๋กœ ์„ค์ •ํ•˜๊ฒ ๋‹ค๋Š” ์˜๋ฏธ์ด๋ฉฐ, ๋งŒ์•ฝ ์ง€์ •ํ•˜์ง€ ์•Š์€ ๊ฒฝ์šฐ ์š”์ฒญ์— ๋Œ€ํ•ด ๊ฐ€์žฅ ๊ตฌ์ฒด์ ์ธ ์„œ๋ฒ„ ๋ธ”๋ก์„ ์ฐพ์œผ๋ ค๊ณ  ๋งค์นญ์„ ์‹œ๋„ํ•œ๋‹ค.

โญ๏ธ ์—ฌ๊ธฐ์„œ, ๊ธฐ๋ณธ ์„œ๋ฒ„ ๋ธ”๋ก์ด๋ผ๋Š” ๊ฑด ์•„๋ฌด๊ฒƒ๋„ ๋งค์นญ๋˜์ง€ ์•Š์„ ๋•Œ ์‚ฌ์šฉํ•œ๋‹ค๋Š” ์˜๋ฏธ์ด๋‹ค.

 

1. ์š”์ฒญํ•œ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„๊ณผ ์ผ์น˜ํ•˜๋Š” server_name ์ง€์‹œ๋ฌธ์ด ์žˆ๋Š” ์„œ๋ฒ„ ๋ธ”๋ก ์ง€์ •
2. ์š”์ฒญ๋œ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„๊ณผ ์ผ์น˜ํ•˜๋Š” ์™€์ผ๋“œ์นด๋“œ server_name ์ง€์‹œ๋ฌธ์ด ์žˆ๋Š” ์„œ๋ฒ„ ๋ธ”๋ก ์ง€์ •
3. ๊ธฐ๋ณธ ์„œ๋ฒ„ ๋ธ”๋ก (default_server)

 

์˜ˆ๋ฅผ ๋“ค์–ด์„œ, journey-shop.kro.kr์œผ๋กœ ์š”์ฒญ์ด ๋“ค์–ด์˜จ๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ˆœ์„œ๋กœ ๋งค์นญ๋œ๋‹ค.

server {
    listen 80;
    server_name *.journey-shop.kro.kr;
}

server {
    listen 80;
    server_name *.journey-shop.kro.kr;
}

server {
    listen 80 default_server;
}

์ด๋ ‡๊ฒŒ 3๊ฐœ์˜ ์„œ๋ฒ„ ๋ธ”๋ก์ด ์žˆ๋‹ค๋ฉด ๊ฐ€์žฅ ๊ตฌ์ฒด์ ์ธ ์ฒซ ๋ฒˆ์งธ ๋ธ”๋ก์ด ์„ ํƒ๋  ๊ฒƒ์ด๋ฉฐ, ๋งŒ์•ฝ ์ฒซ ๋ฒˆ์งธ ๋ธ”๋ก์ด ์ž˜๋ชป๋˜์—ˆ๋‹ค๋ฉด ๋‘ ๋ฒˆ์งธ ๋ธ”๋ก์œผ๋กœ, ๋‘ ๋ฒˆ์งธ ๋ธ”๋ก๋„ ์ž˜๋ชป๋˜์—ˆ๋‹ค๋ฉด default_server๋กœ ์„ค์ •๋˜์–ด ์žˆ๋Š” ์„ธ ๋ฒˆ์งธ ๋ธ”๋ก์ด ์„ ํƒ๋œ๋‹ค.

 

 

์‚ฌ์‹ค ์ด ๋ถ€๋ถ„์€ ๊ธฐ๋ณธ์œผ๋กœ ์ œ๊ณตํ•˜๋Š” ๋ถ€๋ถ„์„ ๋ณ„๋„๋กœ ๊ฑด๋“ค์ง€ ์•Š์•˜๋‹ค.

root์˜ ๊ฒฝ์šฐ ์ •์  ํŒŒ์ผ์— ๋Œ€ํ•œ ๊ธฐ๋ณธ ๊ฒฝ๋กœ์ด๊ธฐ ๋•Œ๋ฌธ์—, journey-shop.kro.kr/index.html ์š”์ฒญ์ด ๋“ค์–ด์˜จ๋‹ค๋ฉด  /var/www/html/index.html์—์„œ ํŒŒ์ผ์„ ์ฐพ๊ฒŒ ๋œ๋‹ค.

index์˜ ๊ฒฝ์šฐ, request์— ์•„๋ฌด ํŒŒ์ผ๋„ ์ง€์ •ํ•˜์ง€ ์•Š์€ ์ƒํƒœ๋กœ ์š”์ฒญ์ด ๋“ค์–ด์˜จ๋‹ค๋ฉด /var/www/html/index, /var/www/html/index.html, /var/www/html/index.htm, /var/www/html/index.nginx-debian.html ํŒŒ์ผ์„ ์ˆœ์„œ๋Œ€๋กœ ์ฐพ์œผ๋ฉฐ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

 

 

server_name์—๋Š” ์—ฌ๋Ÿฌ ๋„๋ฉ”์ธ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค.

# 2๊ฐœ์˜ ๋„๋ฉ”์ธ์— ๋Œ€ํ•ด์„œ ์ฒ˜๋ฆฌ
server_name journey-shop.kro.kr www.journey-shop.kro.kr

# .journey-shop.kro.kr๊ณผ ๋™์ผํ•˜๋‹ค. ์„œ๋ธŒ๋„๋ฉ”์ธ์— ๋Œ€ํ•œ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.
server_name *.journey-shop.kro.kr

# ํŠน์ • ์ด๋ฆ„์œผ๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋„๋ฉ”์ธ์— ๋Œ€ํ•œ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.
server_name journey-shop.kro.kr.*

์ฐธ๊ณ ๋กœ, nginx์˜ ๊ฒฝ์šฐ ๋‹จ์ˆœํžˆ HTTP ํ—ค๋”์— ์žˆ๋Š” ์ด๋ฆ„์„ ํ†ตํ•ด ์š”์ฒญ์— ์‘๋‹ตํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋„๋ฉ”์ธ ์ด๋ฆ„์ด ์œ ํšจํ•œ์ง€๋Š” ์•Œ ์ˆ˜ ์—†๋‹ค.

๊ทธ๋ž˜์„œ ์œ ํšจํ•˜์ง€ ์•Š์€ ๋„๋ฉ”์ธ ์ด๋ฆ„์„ server_name์— ์ง€์ •ํ•  ์ˆ˜๋„ ์žˆ๋‹ค. (๋ฌผ๋ก  ์—๋Ÿฌ ํŽ˜์ด์ง€๋กœ ๊ฐ€๊ฒ ์ง€๋งŒ?)

 

 

์•„๊นŒ crt๋ฅผ ํ†ตํ•ด ๋ณด๋ƒˆ๋˜ ์ธ์ฆ์„œ์™€ ํ‚ค๋ฅผ ์—ฌ๊ธฐ์—์„œ ์ง€์ •ํ•ด์ค€๋‹ค.

๊ฐ€์žฅ ๋งˆ์ง€๋ง‰ ์˜ต์…˜์˜ ๊ฒฝ์šฐ ์„œ๋ฒ„์—์„œ ์ง€์ •ํ•œ ์•”ํ˜ธํ™” ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์šฐ์„ ํ•œ๋‹ค๋Š” ์˜๋ฏธ์ด๋ฉฐ, off๋กœ ์„ค์ •ํ•˜๋ฉด ์™ธ๋ถ€์—์„œ ์•ฝํ™”๋œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ณต๊ฒฉํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ์›ฌ๋งŒํ•˜๋ฉด ํ‚ค๋Š” ๊ฒŒ ์ข‹๋‹ค.

์ฐธ๊ณ ๋กœ, ssl_protocols์„ ํ†ตํ•ด ํ”„๋กœํ† ์ฝœ์„ ์ง€์ •ํ•˜๊ฑฐ๋‚˜ ssl_ciphers๋ฅผ ํ†ตํ•ด ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ง€์ •๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.

 

 

์—ฌ๊ธฐ์„œ proxy_pass๋ฅผ ํ†ตํ•ด http, https๋กœ ๋“ค์–ด์˜จ ์š”์ฒญ์— ๋Œ€ํ•ด์„œ ์šฐ๋ฆฌ๊ฐ€ ์Šคํ”„๋ง๋ถ€ํŠธ๋ฅผ ๋„์šด 8080์œผ๋กœ ํฌ์›Œ๋”ฉ๋˜๋„๋ก ์„ค์ •ํ•˜์˜€๋‹ค.

์ฆ‰, ๋ฐฑ์—”๋“œ ์„œ๋ฒ„๋กœ ์š”์ฒญ์„ ๋ณด๋‚ธ๋‹ค๊ณ  ์ƒ๊ฐํ•˜๋ฉด ๋œ๋‹ค.

 

์—ฌ๊ธฐ์„œ ํ˜ธ์ŠคํŠธ ์ด๋ฆ„์ด ์กฐ๊ธˆ ํ—ท๊ฐˆ๋ ธ์—ˆ๋Š”๋ฐ, ์‚ฌ์šฉ์ž๊ฐ€ journey-shop.kro.kr์— ์ ‘์†ํ–ˆ์„ ๋•Œ ๋‚จ๋Š” http ํ—ค๋”์˜ host ๊ฐ’ = journey-shop.kro.kr์„ ํ”„๋ก์‹œ ํ—ค๋”๋กœ ์ง€์ •ํ•ด์ฃผ๋Š” ๊ฒƒ์ด์—ˆ๋‹ค. ์ฆ‰, ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์–ด๋””๋กœ ์š”์ฒญ์„ ๋ณด๋ƒˆ๋Š”์ง€ ๊ธฐ๋กํ•˜๋Š” ๊ฒƒ์ด๋ผ๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค.

 

 

๊ฐ€์žฅ ๋งˆ์ง€๋ง‰ ๋ธ”๋ก์ด๋‹ค!

์œ„์—์„œ ์„ค๋ช…ํ–ˆ๋˜ ๊ฒƒ์ฒ˜๋Ÿผ journey-shop.kro.kr๋กœ ์š”์ฒญ์ด ๋“ค์–ด์˜ค๋ฉด ๊ฐ€์žฅ ๊ตฌ์ฒด์ ์ธ server_name์ด ์ง€์ •๋œ ์ด ๋ธ”๋ก์ด ๋งค์นญ๋œ๋‹ค.

๋‚˜๋Š” http ์š”์ฒญ์„ ๋ชจ๋‘ https๋กœ ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ์‹œํ‚ค๊ธฐ ์œ„ํ•ด์„œ ์œ„์™€ ๊ฐ™์ด ๋งŒ๋“ค์–ด์ฃผ์—ˆ๋‹ค.

 

host์˜ ๊ฒฝ์šฐ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์—์„œ Host ํ—ค๋” ๊ฐ’์„ ์˜๋ฏธํ•˜๋ฉฐ, request_uri๋Š” ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์š”์ฒญํ•œ URI์ด๋‹ค.

nginx์—์„œ ์ž๋™์œผ๋กœ ์„ค์ •ํ•ด์ฃผ๋Š” ๊ฐ’์ด๊ธฐ ๋•Œ๋ฌธ์— ๋ณ„๋„๋กœ ์žฌ์ •์˜ํ•  ํ•„์š”๋Š” ์—†๋‹ค.

 

๐Ÿ’ก ์ฐธ๊ณ ๋กœ, URI์˜ ๊ฒฝ์šฐ ์ฟผ๋ฆฌ ํŒŒ๋ผ๋ฏธํ„ฐ๋„ ํฌํ•จํ•œ๋‹ค.
ex) https://journey-shop.kro.kr/products?name='์น˜ํ‚จ'

host: https://journey-shop.kro.kr
request_uri: journey-shop.kro.kr/products?name='์น˜ํ‚จ'

 

๋‹ค ๋๋‚ฌ๋‹ค! ์ด์ œ ๋ธŒ๋ผ์šฐ์ €์—์„œ journey-shop.kro.kr/admin๋กœ ๋“ค์–ด๊ฐ€๋ฉด ๋ฐ”๋กœ https๋กœ ๋””๋ผ์ด๋ ‰ํŠธ๋œ๋‹ค!

 


 

์‚ฌ์‹ค ์บ ํผ์Šค์—์„œ ์ผ์–ด์•ผ ํ–ˆ๋Š”๋ฐ... 

๋‹ค ๋ชป ์จ์„œ ๋’ค๋Šฆ๊ฒŒ ๊ธฐ์–ต์„ ์˜์กดํ•˜์—ฌ ์ž‘์„ฑํ•˜์˜€๋‹ค ๐Ÿ˜…

์บ ํผ์Šค ๋“ฑ๊ตํ•˜๋ฉด www๋„ ์ถ”๊ฐ€ํ•ด์•ผ๊ฒ ๋‹ค ^^...

 

 

 

Comments