์ธํ”„๋ผ

[AWS] ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ, ๋„๋ฉ”์ธ ์—†์ด EC2 ์„œ๋ฒ„ HTTPS ์—ฐ๊ฒฐ

HHRR 2024. 7. 3. 13:29

 

๊ฐœ์š”

 

ํ˜„์žฌ ๋ฐฑ์—”๋“œ ์„œ๋ฒ„๋Š” EC2๋กœ ๋ฐฐํฌํ•ด๋†“์€ ์ƒํƒœ์ด๊ณ , SSL ์ธ์ฆ์„œ๋กœ Https ๋ถ™์—ฌ์•ผ Https ์ ์šฉ๋œ ํ”„๋ก ํŠธ๋ž‘ ํ†ต์‹ ํ•  ๋•Œ Mixed Content ์—๋Ÿฌ๊ฐ€ ์•ˆ๋‚œ๋‹ค.

ํ”„๋ก ํŠธ๋Š” S3๋กœ ๋ฐฐํฌํ•ด์„œ ACM์œผ๋กœ SSL ์ธ์ฆ์„œ ๋ฐœ๊ธ‰๋ฐ›์•„์„œ ๋ฐ”๋กœ Route53์ด๋ž‘ Cloud Front๋กœ ์—ฐ๊ฒฐํ•ด์„œ ์ ์šฉํ•˜๊ธฐ ์‰ฌ์› ๋Š”๋ฐ, ๋ฐฑ์—”๋“œ๋Š” EC2๋กœ ๋ฐฐํฌํ•ด์„œ ๋„๋ฉ”์ธ ๊ตฌ๋งคํ›„ ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ Route53 AEM์œผ๋กœ ๋ถ™์—ฌ์•ผ ํ•˜๋Š”๊ฒŒ ์ •์„์ด๋ผ๋Š”๋ฐ ๋กœ๋“œ๋ฐธ๋Ÿฐ์„œ ๋‹ฌ๊ธฐ ์‹ซ์–ด์„œ ๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์„ ์ฐพ์•„๋ดค๋‹ค..

 

Caddy๋ž€?

Caddy๋Š” ์˜คํ”ˆ์†Œ์Šค๋กœ Https๋ฅผ ๋ถ™์—ฌ์ฃผ๋Š” DNS๋‹ค. systemd๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ Linux ๋ฐฐํฌํŒ์—์„œ Caddy๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ๋„๋ฉ”์ธ ๊ตฌ๋งค ์—†์ด Https๋ฅผ ๋‹ฌ ์ˆ˜ ์žˆ๋‹ค!

 

๊ณผ์ •

 

1. EC2์— Caddy ์„ค์น˜ํ•˜๊ธฐ

curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key'  | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install caddy

 

2. Caddy config ํŒŒ์ผ ์ƒ์„ฑ

- https://caddyserver.com/docs/running ์ฐธ๊ณ 

1) caddy.service ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์ค€๋‹ค.

  ์œ„์น˜ : /etc/systemd/system/caddy.service 

[Unit]
Description=Caddy
Documentation=https://caddyserver.com/docs/
After=network.target network-online.target
Requires=network-online.target

[Service]
Type=notify
User=caddy
Group=caddy
ExecStart=/usr/bin/caddy run --environ --config /etc/caddy/Caddyfile
ExecReload=/usr/bin/caddy reload --config /etc/caddy/Caddyfile --force
TimeoutStopSec=5s
LimitNOFILE=1048576
LimitNPROC=512
PrivateTmp=true
ProtectSystem=full
AmbientCapabilities=CAP_NET_BIND_SERVICE

[Install]
WantedBy=multi-user.target
ubuntu@ip-172-31-38-42:~$

 

 

2) Caddyfile ๋งŒ๋“ค๊ธฐ

- ๊ธฐ์กด์— ์กด์žฌํ•˜๋Š”๊ฒŒ ์žˆ์œผ๋ฉด ์‚ญ์ œํ•˜๊ณ  ๋‹ค์‹œ ๋งŒ๋“ค์–ด์ค€๋‹ค.

- reverse_proxy localhost:8080 ๋กœ ๋“ค์–ด์˜ค๋Š” ์š”์ฒญ์„ 8080ํฌํŠธ๋กœ ํฌ์›Œ๋”ฉํ•ด์ค€๋‹ค.

- bind: address already in use ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์–ด admin์„ ์ถ”๊ฐ€ํ•ด์ค€๋‹ค.

{
    admin 0.0.0.0:2020
}
15.164.30.195.nip.io {
    reverse_proxy localhost:8080
}

 

3. Caddy ์‹คํ–‰

- ์„œ๋น„์Šค๋ฅผ ํ™œ์„ฑํ™” ์‹œํ‚จ๋‹ค.

sudo systemctl daemon-reload
sudo systemctl enable --now caddy
systemctl status -l caddy

- ์„œ๋น„์Šค๋ฅผ ์‹คํ–‰ํ•œ๋‹ค.

- ์•„๋ž˜์™€ ๊ฐ™์ด ๋‚˜์˜ค๋ฉด ์„œ๋น„์Šค๊ฐ€ ์ •์ƒ ์‹คํ–‰ ๋œ ๊ฒƒ

sudo caddy start

 

4. ์‹คํ–‰ ํ™•์ธ

  • https://{ec2 ํผ๋ธ”๋ฆญip}.nip.io ๋กœ ์‹คํ–‰๋œ๋‹ค.
  • ์ฃผ์˜ํ•  ์ ์€ ๋ฐฑ์—”๋“œ EC2 ๋ณด์•ˆ๊ทธ๋ฃน์œผ๋กœ 443 ํฌํŠธ๋ฅผ ์—ด์–ด์ฃผ๊ธฐ

 

https๋กœ ์ •์ƒ ์ž‘๋™ํ•˜๋Š” ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.

 

์ฐธ๊ณ 
- https://velog.io/@miro7923/AWS-EC2-%EC%84%9C%EB%B2%84-%EB%8F%84%EB%A9%94%EC%9D%B8-%EC%97%86%EC%9D%B4-https-%EB%B6%99%EC%9D%B4%EA%B8%B0
- https://caddyserver.com/docs/running