๐Ÿšข Amazon S3 ๋ฐ Cloudflare ๊ด€๋ฆฌ ์ •์  ์›น ์‚ฌ์ดํŠธ ์‚ฌ์šฉ ๋ฐฉ๋ฒ•โ˜

11627 ๋‹จ์–ด
์•ˆ๋…•ํ•˜์„ธ์š”!SSL ์ธ์ฆ์„œ๋ฅผ ์–ป๊ธฐ ์œ„ํ•ด ์‚ฌ์ดํŠธ๋ฅผ s3+cloudflare๋กœ ์ด๋™ํ•ฉ๋‹ˆ๋‹ค.์–ด๋–ป๊ฒŒ ํ•˜๋Š”์ง€ ์•Œ๊ณ  ์‹ถ์œผ์„ธ์š”?๋‚˜๋Š” ๋„ˆํฌ๋“ค์—๊ฒŒ ๋ณด์—ฌ์ค„ ๊ฒƒ์ด๋‹ค.
๋จผ์ € AWS ์ฝ˜์†”์— ๊ด€๋ฆฌ์ž๋กœ ๋กœ๊ทธ์ธํ•  ์ƒˆ ์Šคํ† ๋ฆฌ์ง€๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

Bucket ์ž‘์„ฑ


์„œ๋น„์Šค ๋ฅผ ํด๋ฆญํ•˜๊ณ  ์Šคํ† ๋ฆฌ์ง€ ์„น์…˜์—์„œ S3 ์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.

ํŽ˜์ด์ง€์—์„œ ์˜ค๋ฅธ์ชฝ ๊ตฌ์„์— ์žˆ๋Š” Create Bucket ์„ ํด๋ฆญํ•œ ๋‹ค์Œ:
  • ๋‚ด ์ƒํƒœ์—์„œ Bucket name ๋ณ€๊ฒฝwww.themaymeow.com
  • AWS ์ง€์—ญ
  • ์„ ํƒ
  • ๋ชจ๋“  ๊ณต์šฉ ์•ก์„ธ์Šค ์ฐจ๋‹จ ์„ ํƒ ์ทจ์†Œ
  • ๊ธฐํƒ€ ๋ณ€๊ฒฝ ์‚ฌํ•ญ ์—†์Œ
  • ํด๋ฆญํ•˜์—ฌ ํ†ต ์ƒ์„ฑ
  • ์Šคํ† ๋ฆฌ์ง€ ํ†ต ์†์„ฑ ์—…๋ฐ์ดํŠธ


    ๋ฒ„ํ‚ท ๋ชฉ๋ก์„ ๋ณผ ์ˆ˜ ์žˆ์œผ๋ฏ€๋กœ ๋ฒ„ํ‚ท์„ ์„ ํƒํ•˜๊ณ  ๋ฒ„ํ‚ท ํŽ˜์ด์ง€์—์„œProperties ์˜ต์…˜์„ ์„ ํƒํ•˜์‹ญ์‹œ์˜ค
  • Bucket overview์—์„œ ์•„๋งˆ์กด ์ž์› ์ด๋ฆ„ ARN์„ ๋ณต์ œํ•ฉ๋‹ˆ๋‹ค.๋‚˜์ค‘์— ํ•„์š”
  • ์ •์  ์‚ฌ์ดํŠธ ์œ„ํƒ ๊ด€๋ฆฌ ํด๋ฆญ ํŽธ์ง‘
  • ์œผ๋กœ ์•„๋ž˜๋กœ ์Šคํฌ๋กค
  • ์ •์  ์›น ์‚ฌ์ดํŠธ ํ˜ธ์ŠคํŒ… ์„ค์ •
  • ๊ด€๋ฆฌํ˜• ์œ ํ˜•์€ "๊ด€๋ฆฌํ˜• ์ •์  ์‚ฌ์ดํŠธ"
  • ์ธ๋ฑ์Šค ๋ฌธ์„œ ์„ค์ •index.html
  • ๊ธฐํƒ€ ์‚ฌ๋ฌผ์€ ๋ณ€ํ•˜์ง€ ์•Š๋Š”๋‹ค
  • ์•„๋ž˜๋กœ ์Šคํฌ๋กค ๋ฐ ํด๋ฆญํ•˜์—ฌ ๋ณ€๊ฒฝ ๋‚ด์šฉ ์ €์žฅ
  • ๋‹น์‹ ์˜ ์‚ฌ์ดํŠธ ๋‹จ์ ์„ ์–ด๋”˜๊ฐ€๋กœ ๋ณต์‚ฌ

  • ๊ถŒํ•œ ์—…๋ฐ์ดํŠธ


    ๋‘ ๋ฒˆ์งธ ํƒญ ์‚ฌ์šฉ ๊ถŒํ•œ์„ ์„ ํƒํ•˜์—ฌ Bucket ์ •์ฑ…์œผ๋กœ ์Šคํฌ๋กคํ•ฉ๋‹ˆ๋‹ค. ํŽธ์ง‘์„ ํด๋ฆญํ•˜๊ณ  ๋‹ค์Œ ์ •์ฑ…์„ ๋ถ™์—ฌ ๋„ฃ์Šต๋‹ˆ๋‹ค.
    {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Sid": "Public",
                "Effect": "Allow",
                "Principal": "*",
                "Action": "s3:GetObject",
                "Resource": "<change-me-to-youw-ARN>/*"
            }
        ]
    }
    
  • ๋ณต์ œ ARN ์—…๋ฐ์ดํŠธ
  • cnages ์ €์žฅ
  • ์„ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.
    ์ด๊ฒƒ์ด ๋ฒ„ํ‚ท ์„ค์ •์˜ ์ „๋ถ€์ž…๋‹ˆ๋‹ค.๋ฒ„ํ‚ท์— ๋‚ด์šฉ์„ ์“ธ ์ˆ˜ ์žˆ๋Š” ์‚ฌ์šฉ์ž๋ฅผ ๋งŒ๋“ค์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

    ๋ฐฐํฌ ์‚ฌ์šฉ์ž


    ๋”ฐ๋ผ์„œ ID ๋ฐ ์•ก์„ธ์Šค ๊ด€๋ฆฌ IAM์„ ๊ฒ€์ƒ‰ํ•˜๊ณ  ์—ฝ๋‹ˆ๋‹ค.

    ์ •์ฑ… ์ƒ์„ฑ


    ์šฐ์„ , ์ •์ฑ…์„ ๋งŒ๋“ค์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.์™ผ์ชฝ ๋ฉ”๋‰ด์—์„œ ์ •์ฑ…์„ ์ฐพ์•„ ์—ฝ๋‹ˆ๋‹ค.
  • ์ •์ฑ… ์ƒ์„ฑ ํด๋ฆญ
  • JSON ํƒญ ์„ ํƒ
  • ์•„๋ž˜ ํ•ญ๋ชฉ ๋ถ™์—ฌ๋„ฃ๊ธฐ ๋ฐ ARN ๋ณ€๊ฒฝ
  • {
        "Version": "2012-10-17",
        "Statement": [
            {
                "Effect": "Allow",
                "Action": [
                    "s3:ListAllMyBuckets"
                ],
                "Resource": "arn:aws:s3:::*"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "s3:ListBucket",
                    "s3:GetBucketLocation"
                ],
                "Resource": "<change-me-to-youw-ARN>"
            },
            {
                "Effect": "Allow",
                "Action": [
                    "s3:PutObject",
                    "s3:PutObjectAcl",
                    "s3:GetObject",
                    "s3:GetObjectAcl",
                    "s3:DeleteObject"
                ],
                "Resource": "<change-me-to-youw-ARN>/*"
            }
        ]
    }
    
    ์ค‘์š”ํ•œ ๊ฒƒ์€ "Resource": "<change-me-to-youw-ARN>"๊ณผ"Resource": "<change-me-to-youw-ARN>/*"๊ฐ€ ์˜ณ๋‹ค๋Š” ๊ฒƒ์„ ๋ณด๊ฒŒ ๋  ๊ฒƒ์ด๋‹ค. ๋‘ ๋ฒˆ์งธ/*๋ฅผ ์ œ๊ฑฐํ•˜์ง€ ๋งˆ๋ผ.
  • ๋‹ค์Œ ํ‘œ์‹ ํด๋ฆญ
  • ๋‹ค์Œ ๊ฐ์‚ฌ ์ •์ฑ… ํด๋ฆญ
  • ์—…๋ฐ์ดํŠธ ์ด๋ฆ„
  • ์ •์ฑ… ์ƒ์„ฑ ํด๋ฆญ

  • ์‚ฌ์šฉ์ž ์ž‘์„ฑ


    ์™ผ์ชฝ ๋ฉ”๋‰ด์—์„œ ์‚ฌ์šฉ์ž๋ฅผ ์„ ํƒํ•œ ๋‹ค์Œ ์‚ฌ์šฉ์ž ์ถ”๊ฐ€ ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.
  • ์ด๋ฆ„ ๋ณ€๊ฒฝ
  • ์•ก์„ธ์Šค ์œ ํ˜• ์„ ํƒ๊ธฐ ์•ก์„ธ์Šค
  • ๋‹ค์Œ: ์‚ฌ์šฉ ๊ถŒํ•œ ํด๋ฆญ
  • ํด๋ฆญํ•˜์—ฌ ๊ทธ๋ฃน ๋งŒ๋“ค๊ธฐ
  • ๊ทธ๋ฃน ์ด๋ฆ„ ๋ณ€๊ฒฝ
  • ์ƒ์„ฑํ•œ ์ •์ฑ…์„ ์„ ํƒํ•ฉ๋‹ˆ๋‹ค.์‚ฌ์šฉ์ž๊ฐ€ ๋งŒ๋“  ์ •์ฑ…๋งŒ ํ‘œ์‹œํ•˜๋ ค๋ฉด ๊ฒ€์ƒ‰ ๋˜๋Š” ํ•„ํ„ฐ๋ง์„ ์‚ฌ์šฉํ•˜์‹ญ์‹œ์˜ค
  • .
  • ํด๋ฆญํ•˜์—ฌ gourp ๋งŒ๋“ค๊ธฐ
  • ๋‹ค์Œ ํ‘œ์‹ ํด๋ฆญ
  • ๋‹ค์Œ ๋‹จ๊ณ„๋ฅผ ํด๋ฆญํ•˜์—ฌ ๊ฒ€ํ† 
  • ์‚ฌ์šฉ์ž ์ƒ์„ฑ ํด๋ฆญ
  • ์•ก์„ธ์Šค ํ‚ค ID์™€ ๋น„๋ฐ€ ์•ก์„ธ์Šค ํ‚ค๋ฅผ ์–ด๋””๋กœ ๋ณต์‚ฌํ•ฉ๋‹ˆ๋‹ค
  • .
  • ๋‹ซ๊ธฐ
  • ์ž, ์ด๊ฒƒ์ด AWS์˜ ๋ชจ๋“  ์„ค์ •์ž…๋‹ˆ๋‹ค.๋‹ค์Œ ๋‹จ๊ณ„๋Š” Cloudflare์—์„œ ๋„๋ฉ”์ธ์„ ๊ตฌ์„ฑํ•˜๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.

    cloudflare์— ๋„๋ฉ”์ธ ์ถ”๊ฐ€


    cloudflare์— ๋กœ๊ทธ์ธํ•˜๊ณ  ํด๋ฆญํ•˜์—ฌ + ์‚ฌ์ดํŠธ ์ถ”๊ฐ€
  • ๋‹น์‹ ์˜ ์‚ฌ์ดํŠธ์— ๋“ค์–ด๊ฐ€๊ธฐ
  • ์‚ฌ์ดํŠธ ์ถ”๊ฐ€
  • ํด๋ฆญ
  • Cloudflare ์—†์Œ
  • ์„ ํƒ
  • dns ๊ธฐ๋ก์ด ์žˆ์œผ๋ฉดcloudflare์—์„œ ์ด ๊ธฐ๋ก์„ ์ˆ˜์ง‘ํ•˜๋ ค๊ณ  ์‹œ๋„ํ•ฉ๋‹ˆ๋‹ค
  • Privider์— ๋กœ๊ทธ์ธํ•˜๊ณ  ์ด๋ฆ„ ์„œ๋ฒ„๋ฅผ ์—…๋ฐ์ดํŠธํ•ฉ๋‹ˆ๋‹ค
  • Cloudflare์—์„œ ๋„๋ฉ”์ธ์„ ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.(ํŽ˜์ด์ง€์—์„œ ๊ธฐ๋‹ค๋ฆด ์ˆ˜๋„ ์žˆ๊ณ ,clodflare๋ฅผ ์ž ์‹œ ๋‹ซ์„ ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.)ํƒœ์ด๊ฐ€ ์•Œ๋ ค์ค„๊ฒŒ.
  • DNS ๊ทœ์น™ ๊ตฌ์„ฑ


    ๋„ค, ๋Œ์•„์˜ค์‹œ๋ฉด ๋„๋ฉ”์ธ ์ด๋ฆ„์„ ์„ค์ •ํ•˜์…จ์Šต๋‹ˆ๋‹ค.๊ทธ๋ž˜์„œ ๋ˆŒ๋Ÿฌ์„œ ์„ธ ๋ฒˆ์งธ ํƒญ DNS๋ฅผ ์„ ํƒํ•˜์„ธ์š”.
  • ๊ทœ์น™ ์œ ํ˜• CNAME ์ž‘์„ฑ
  • ์ด๋ฆ„ ์„ค์ •www
  • AWS ์‚ฌ์ดํŠธ ๋…ธ๋“œ์˜ ๋ชฉํ‘œ๊ฐ€ ์„ค์ •๋˜์ง€ ์•Š์Œhttps://
  • ํ”„๋ก์‹œ ์ƒํƒœ๊ฐ€ ํ”„๋ก์‹œ๋กœ ์„ค์ •
  • ์ œ2์กฐ ๊ทœ์น™ ์ž‘์„ฑ
  • ์œ ํ˜•์„ CNAME
  • ๋กœ ์„ค์ •
  • ์ด๋ฆ„ ์„ค์ •@
  • ๋ชฉํ‘œ ์„ค์ •www.yourdomain.tld
  • ํ”„๋ก์‹œ ์ƒํƒœ ์„ค์ •
  • SSL/tls ๊ตฌ์„ฑ


    ๋„ค ๋ฒˆ์งธ ํƒญ SSL/TLS ์„ ํƒ
  • ssl/tls ์•”ํ˜ธํ™” ๋ชจ๋“œ๋ฅผ Flexible๋กœ ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค. AWS์—์„œ ์˜จ ์ธ์ฆ์„œ๊ฐ€ ์•„๋‹ˆ๋ผ ์ง์ ‘ ์„œ๋ช…ํ•œ ์ธ์ฆ์„œ
  • ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.

    ํƒญ์—์„œ ๊ฐ€์žฅ์ž๋ฆฌ ์ธ์ฆ์„œ ์„ ํƒ
  • ํ•ญ์ƒ On์œผ๋กœ ์„ค์ •๋œ HTTPS ์‚ฌ์šฉ

  • ํŽ˜์ด์ง€ ๊ทœ์น™ ์„ค์ •


    ๋‹ค์Œ๋„ ๋งˆ์ง€๋ง‰ ์ผ์€ ์šฐ๋ฆฌ์˜ ๋ˆ„๋“œdomain.tld๋ฅผ www.domain.tld๋กœ ๋ฐ”๊พธ๋Š” ๊ฒƒ์ด๋‹ค.
    ๊ทธ๋ž˜์„œ 10ํŽ˜์ด์ง€ ํƒœ๊ทธ ๊ทœ์น™์„ ์„ ํƒํ–ˆ์Šต๋‹ˆ๋‹ค.
  • ํŽ˜์ด์ง€ ๋งŒ๋“ค๊ธฐ ๊ทœ์น™ ํด๋ฆญ
  • ์„ค์ • ๊ทœ์น™์ด ์ผ์น˜ํ•˜๋Š”์ง€ ์—ฌ๋ถ€yourdomain.tld/*
  • ๊ทธ๋ฆฌ๊ณ  ์„ ํƒ ์ „๋‹ฌ Url ์„ค์ •
  • ๋‹ค์Œ ์„ ํƒ ์˜๊ตฌ ๋ฆฌ๋””๋ ‰์…˜ 301
  • ์„ค์ • ๋””์ž์ธ URLhttps://www.yourdomain.tld/$1
  • ์ €์žฅ ๋ฐ ๋ฐฐํฌ๋ฅผ ํด๋ฆญํ•ฉ๋‹ˆ๋‹ค.
  • ๋‹ค์€


    ์ด ๋ชจ๋“  ๊ฒƒ์€ AWS+Cloudflare๋ฅผ ๋‹น์‹ ์˜ ์ •์  ์‚ฌ์ดํŠธ์— ๋“ค์–ด๊ฐ€๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•ด์„œ์ž…๋‹ˆ๋‹ค.

    ๋ณด๋„ˆ์Šค


    ์›น ์‚ฌ์ดํŠธ๋ฅผ AWS์— ๋ฐฐํฌํ•˜๋ ค๋ฉด Minio cliMinio ๋ฐ ๋‹ค์Œ ์Šคํฌ๋ฆฝํŠธ๋ฅผ ์ˆ˜๋™์œผ๋กœ ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ CI/CD๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
    mc config host add cdn https://s3.amazonaws.com <access-id> <secret-access-key> --api s3v4
    mc cp -r paath/to/website/files cdn/bucket-name
    
    ์ด์ œ ์ƒˆ ์›น ์‚ฌ์ดํŠธ๋ฅผ ํƒ์ƒ‰ํ•˜์—ฌ ์ฆ๊ธฐ๊ธฐ๋งŒ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.:)
    ์ตœ์ดˆ ์ถœ์‹œ ์‹œ์ themaymeow.com
    ์‚ฌ์ง„ ์ž‘์„ฑ์žBilly Huynh๊ฐ€ Unsplash

    ์ข‹์€ ์›นํŽ˜์ด์ง€ ์ฆ๊ฒจ์ฐพ๊ธฐ