- หน้าแรก
- ตัวจำลอง CDN
- ยืนยัน
ยืนยัน
หลังจากการปรับใช้งาน ให้รันการตรวจสอบเหล่านี้เพื่อยืนยันว่า edge node ของตัวจำลอง CDN ทำงานได้อย่างถูกต้อง รอ 2-3 นาทีหลังจาก terraform apply เพื่อให้ cloud-init ติดตั้ง NGINX เสร็จสิ้น
การตรวจสอบสุขภาพ
หัวข้อที่มีชื่อว่า “การตรวจสอบสุขภาพ”ตรวจสอบว่า NGINX กำลังทำงานและตอบสนอง:
curl -s "http://<PUBLIC_IP>/health" | jq .ผลลัพธ์ที่คาดหวัง:
{ "status": "healthy", "component": "cdn-edge", "engine": "nginx", "vendor_profiles": [ "akamai", "cloudflare", "cloudfront", "fastly", "azure-front-door" ]}หากใช้ Terraform outputs:
curl -s "$(terraform output -raw health_check_url)" | jq .Cache Miss (คำขอแรก)
หัวข้อที่มีชื่อว่า “Cache Miss (คำขอแรก)”คำขอแรกไปยัง path ใดก็ตามจะเป็น cache miss — edge จะดึงข้อมูลจากต้นทาง:
curl -I "http://<PUBLIC_IP>/"ค้นหา header เหล่านี้ในการตอบสนอง:
X-Cache-Status: MISSX-CDN-Edge: cdn-simulatorMISS หมายความว่าเนื้อหาไม่ได้อยู่ในแคชและถูกดึงมาจากเซิร์ฟเวอร์ต้นทาง
Cache Hit (คำขอถัดไป)
หัวข้อที่มีชื่อว่า “Cache Hit (คำขอถัดไป)”ทำซ้ำคำขอเดิมทันที:
curl -I "http://<PUBLIC_IP>/"header ที่คาดหวัง:
X-Cache-Status: HITX-CDN-Edge: cdn-simulatorHIT ยืนยันว่าการตอบสนองถูกส่งมาจาก NGINX disk cache โดยไม่ได้ติดต่อกับต้นทาง
การตรวจสอบไดเรกทอรีแคช
หัวข้อที่มีชื่อว่า “การตรวจสอบไดเรกทอรีแคช”SSH เข้าไปใน VM เพื่อยืนยันว่าเนื้อหาที่แคชไว้มีอยู่บนดิสก์:
ssh azureuser@<PUBLIC_IP>
# Check cache directory has contentsudo find /var/cache/nginx/cdn -type f | head -20
# Check cache sizesudo du -sh /var/cache/nginx/cdnสถานะ NGINX
หัวข้อที่มีชื่อว่า “สถานะ NGINX”ตรวจสอบว่า NGINX กำลังทำงานและการกำหนดค่าถูกต้อง:
ssh azureuser@<PUBLIC_IP>
# Check service statussudo systemctl status nginx
# Validate configurationsudo nginx -t
# View active connections (if stub_status is enabled)curl -s http://localhost/healthการเชื่อมต่อกับเซิร์ฟเวอร์ต้นทาง
หัวข้อที่มีชื่อว่า “การเชื่อมต่อกับเซิร์ฟเวอร์ต้นทาง”ตรวจสอบว่า edge node สามารถเข้าถึงเซิร์ฟเวอร์ต้นทางได้:
ssh azureuser@<PUBLIC_IP>
# Test connectivity to origin (replace with your origin URL)curl -I "https://your-origin.example.com/"หากล้มเหลว ให้ตรวจสอบ:
- ตัวแปร
origin_serverถูกต้องในการกำหนดค่า Terraform - เซิร์ฟเวอร์ต้นทางอนุญาตการเชื่อมต่อขาเข้าจาก IP สาธารณะของ edge node
- การแก้ไข DNS ทำงานได้จาก VM (
nslookup your-origin.example.com)
ความคืบหน้าของ Cloud-Init
หัวข้อที่มีชื่อว่า “ความคืบหน้าของ Cloud-Init”ติดตามความคืบหน้าการจัดเตรียมผ่าน cloud-init log:
ssh azureuser@<PUBLIC_IP> "tail -f /var/log/cloud-init-progress.log"ขั้นตอนที่คาดหวัง: [init], [nic] (การตรวจจับ NIC แบบไดนามิก), [complete]
หาก cloud-init รายงานข้อผิดพลาด:
ssh azureuser@<PUBLIC_IP> "sudo cloud-init status --long"การทดสอบแบบครบวงจร
หัวข้อที่มีชื่อว่า “การทดสอบแบบครบวงจร”รันวงจรคำขอเต็มรูปแบบและตรวจสอบห่วงโซ่การตอบสนอง:
# First request — MISS (fetches from origin)echo "=== Request 1 (expect MISS) ==="curl -s -o /dev/null -w "HTTP %{http_code} | Cache: %{header:X-Cache-Status}\n" "http://<PUBLIC_IP>/test-path"
# Second request — HIT (served from cache)echo "=== Request 2 (expect HIT) ==="curl -s -o /dev/null -w "HTTP %{http_code} | Cache: %{header:X-Cache-Status}\n" "http://<PUBLIC_IP>/test-path"ผลลัพธ์ที่คาดหวัง:
=== Request 1 (expect MISS) ===HTTP 200 | Cache: MISS=== Request 2 (expect HIT) ===HTTP 200 | Cache: HITการตรวจสอบ Header ของ Vendor
หัวข้อที่มีชื่อว่า “การตรวจสอบ Header ของ Vendor”ตรวจสอบว่า CDN vendor header ทั้งหมดถูกแทรกเข้ามาโดยการร้องขอ path /headers (เมื่อใช้ httpbin.org เป็นต้นทาง):
curl -s "http://<PUBLIC_IP>/headers" | python3 -m json.toolการตอบสนองที่คาดหวังประกอบด้วย header จาก vendor ทั้งห้าราย:
{ "headers": { "True-Client-Ip": "<YOUR_CLIENT_IP>", "Cf-Connecting-Ip": "<YOUR_CLIENT_IP>", "Cf-Ipcountry": "US", "Cf-Ray": "<request_id>-SJC", "Cf-Bot-Score": "85", "Cf-Ja3-Hash": "e7d705a3286e19ea42f587b344ee6865", "Cloudfront-Viewer-Country": "US", "Cloudfront-Viewer-City": "San Jose", "Cloudfront-Is-Desktop-Viewer": "true", "Cloudfront-Is-Mobile-Viewer": "false", "Fastly-Client-Ip": "<YOUR_CLIENT_IP>", "X-Akamai-Edgescape": "georegion=263,country_code=US,...", "X-Azure-Clientip": "<YOUR_CLIENT_IP>", "X-Azure-Fdid": "a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1", "X-Geo-Country-Code": "US" }}การทดสอบการตรวจจับอุปกรณ์
หัวข้อที่มีชื่อว่า “การทดสอบการตรวจจับอุปกรณ์”ทดสอบด้วย User-Agent ของมือถือเพื่อตรวจสอบว่า header การตรวจจับอุปกรณ์เปลี่ยนแปลง:
curl -s "http://<PUBLIC_IP>/headers?device=mobile" \ -H "User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X)" \ | python3 -m json.tool | grep -E "Is-Mobile|Is-Desktop|is_mobile"ผลลัพธ์ที่คาดหวัง:
"Cloudfront-Is-Desktop-Viewer": "false","Cloudfront-Is-Mobile-Viewer": "true",การแก้ไขปัญหา
หัวข้อที่มีชื่อว่า “การแก้ไขปัญหา”NGINX ไม่ทำงาน
หัวข้อที่มีชื่อว่า “NGINX ไม่ทำงาน”ssh azureuser@<PUBLIC_IP>sudo systemctl status nginxsudo journalctl -u nginx --no-pager -n 50Cloud-init ยังไม่เสร็จสิ้น
หัวข้อที่มีชื่อว่า “Cloud-init ยังไม่เสร็จสิ้น”หลังจาก terraform apply cloud-init ใช้เวลา 2-3 นาที ตรวจสอบความคืบหน้า:
ssh azureuser@<PUBLIC_IP>sudo cloud-init statussudo tail -f /var/log/cloud-init-output.logแคชแสดง MISS เสมอ
หัวข้อที่มีชื่อว่า “แคชแสดง MISS เสมอ”- ตรวจสอบว่าต้นทางส่งคืนรหัสตอบสนองที่สามารถแคชได้ (200, 301, 302)
- ตรวจสอบว่าต้นทางไม่ส่ง header
Cache-Control: no-cacheหรือno-store - ตรวจสอบ NGINX error logs:
sudo tail -f /var/log/nginx/error.log
การเชื่อมต่อถูกปฏิเสธที่ port 80/443
หัวข้อที่มีชื่อว่า “การเชื่อมต่อถูกปฏิเสธที่ port 80/443”- ตรวจสอบว่ากฎ NSG ถูกใช้งาน:
az network nsg rule list --nsg-name "$(terraform output -raw nsg_name)" --resource-group "$(terraform output -raw resource_group_name)" -o table - ตรวจสอบว่า NGINX กำลังรับฟัง:
ssh azureuser@<PUBLIC_IP> "sudo ss -tlnp | grep nginx"