0Pricing
AWS for Backend Developers (EC2, S3, RDS, Lambda) · บทเรียน

การโฮสต์เว็บไซต์สแตติกและการส่งมอบด้วย CDN

ให้บริการเว็บไซต์สแตติกโดยตรงจากบักเก็ต S3 และเร่งการส่งมอบทั่วโลกด้วย CDN CloudFront ที่อยู่ด้านหน้า

การโฮสต์เว็บไซต์สแตติกและการส่งมอบด้วย CDN เป็นบทเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) ฟรีบน CoddyKit นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส AWS for Backend Developers (EC2, S3, RDS, Lambda) มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

S3 as a Web Server

Beyond storing files, S3 can host a static website, HTML, CSS, JS, and images, with no servers to manage. It is cheap, scalable, and a perfect fit for single-page apps and documentation sites.

Enabling Static Hosting

You enable the static website hosting feature on the bucket and specify an index document (the home page) and an error document.

Index and Error Documents

The index document (often index.html) is served for the root and folder URLs. The error document handles 4xx responses, useful for SPA routing where you point errors back to index.html.

Uploading Your Site

Sync your build output into the bucket. The AWS CLI sync command uploads only changed files.

aws s3 sync ./dist s3://my-site-bucket --delete

Content Types Matter

S3 serves files with the Content-Type stored as metadata. If a CSS file is served as plain text, browsers ignore it. The CLI usually infers types, but verify for unusual extensions.

The Website Endpoint

Static hosting exposes a regional website endpoint URL. It is HTTP only and not ideal for production, which is exactly why we add a CDN next.

http://my-site-bucket.s3-website-us-east-1.amazonaws.com

Introducing CloudFront

CloudFront is AWS's content delivery network. It caches your site at edge locations worldwide, so users get fast responses from a nearby server and your bucket sees less load.

Origins and Distributions

A CloudFront distribution points at an origin (your S3 bucket). CloudFront fetches from the origin on a cache miss and serves the cached copy on subsequent requests.

HTTPS and Custom Domains

CloudFront gives you free HTTPS via AWS Certificate Manager and lets you attach a custom domain like www.example.com, things the raw S3 endpoint cannot do.

Locking Down the Bucket

For security, keep the bucket private and let only CloudFront read it using an Origin Access Control (OAC). Visitors reach content through the CDN, never the bucket directly.

Cache Invalidation

CloudFront caches aggressively. After deploying new content, invalidate the cache so users get the latest version instead of a stale copy.

aws cloudfront create-invalidation \
  --distribution-id E123ABC \
  --paths "/*"

Quick Check

Test your static hosting knowledge.

Recap: Global Static Sites

You can now ship a static site on AWS:

  • Enable S3 static website hosting with index/error documents.
  • aws s3 sync deploys your build.
  • CloudFront adds edge caching, HTTPS, and custom domains.
  • Use OAC to keep the bucket private and invalidate the cache on deploy.

คำถามที่พบบ่อย

บทเรียน “การโฮสต์เว็บไซต์สแตติกและการส่งมอบด้วย CDN” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “การโฮสต์เว็บไซต์สแตติกและการส่งมอบด้วย CDN” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส AWS for Backend Developers (EC2, S3, RDS, Lambda) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส AWS for Backend Developers (EC2, S3, RDS, Lambda) มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “การโฮสต์เว็บไซต์สแตติกและการส่งมอบด้วย CDN”

ให้บริการเว็บไซต์สแตติกโดยตรงจากบักเก็ต S3 และเร่งการส่งมอบทั่วโลกด้วย CDN CloudFront ที่อยู่ด้านหน้า คุณปฏิบัติ AWS for Backend Developers (EC2, S3, RDS, Lambda) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน AWS for Backend Developers (EC2, S3, RDS, Lambda) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 4 จากทั้งหมด 4 บทเรียน

บทเรียน “การโฮสต์เว็บไซต์สแตติกและการส่งมอบด้วย CDN” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) นี้ได้ไหม

ได้ บทเรียน AWS for Backend Developers (EC2, S3, RDS, Lambda) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ทำความเข้าใจบักเก็ตและออบเจ็กต์ของ S3
  2. การกำหนดเวอร์ชันและนโยบายวงจรชีวิตของ S3
  3. การรักษาความปลอดภัยการเข้าถึงข้อมูล S3
  4. การโฮสต์เว็บไซต์สแตติกและการส่งมอบด้วย CDN
← กลับไปที่ AWS for Backend Developers (EC2, S3, RDS, Lambda)