ข้ามไปยังเนื้อหา

ยืนยัน

หลังจากการปรับใช้งาน ให้รันการตรวจสอบเหล่านี้เพื่อยืนยันว่า edge node ของตัวจำลอง CDN ทำงานได้อย่างถูกต้อง รอ 2-3 นาทีหลังจาก terraform apply เพื่อให้ cloud-init ติดตั้ง NGINX เสร็จสิ้น

ตรวจสอบว่า NGINX กำลังทำงานและตอบสนอง:

Terminal window
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:

Terminal window
curl -s "$(terraform output -raw health_check_url)" | jq .

คำขอแรกไปยัง path ใดก็ตามจะเป็น cache miss — edge จะดึงข้อมูลจากต้นทาง:

Terminal window
curl -I "http://<PUBLIC_IP>/"

ค้นหา header เหล่านี้ในการตอบสนอง:

X-Cache-Status: MISS
X-CDN-Edge: cdn-simulator

MISS หมายความว่าเนื้อหาไม่ได้อยู่ในแคชและถูกดึงมาจากเซิร์ฟเวอร์ต้นทาง

ทำซ้ำคำขอเดิมทันที:

Terminal window
curl -I "http://<PUBLIC_IP>/"

header ที่คาดหวัง:

X-Cache-Status: HIT
X-CDN-Edge: cdn-simulator

HIT ยืนยันว่าการตอบสนองถูกส่งมาจาก NGINX disk cache โดยไม่ได้ติดต่อกับต้นทาง

SSH เข้าไปใน VM เพื่อยืนยันว่าเนื้อหาที่แคชไว้มีอยู่บนดิสก์:

Terminal window
ssh azureuser@<PUBLIC_IP>
# Check cache directory has content
sudo find /var/cache/nginx/cdn -type f | head -20
# Check cache size
sudo du -sh /var/cache/nginx/cdn

ตรวจสอบว่า NGINX กำลังทำงานและการกำหนดค่าถูกต้อง:

Terminal window
ssh azureuser@<PUBLIC_IP>
# Check service status
sudo systemctl status nginx
# Validate configuration
sudo nginx -t
# View active connections (if stub_status is enabled)
curl -s http://localhost/health

ตรวจสอบว่า edge node สามารถเข้าถึงเซิร์ฟเวอร์ต้นทางได้:

Terminal window
ssh azureuser@<PUBLIC_IP>
# Test connectivity to origin (replace with your origin URL)
curl -I "https://your-origin.example.com/"

หากล้มเหลว ให้ตรวจสอบ:

  1. ตัวแปร origin_server ถูกต้องในการกำหนดค่า Terraform
  2. เซิร์ฟเวอร์ต้นทางอนุญาตการเชื่อมต่อขาเข้าจาก IP สาธารณะของ edge node
  3. การแก้ไข DNS ทำงานได้จาก VM (nslookup your-origin.example.com)

ติดตามความคืบหน้าการจัดเตรียมผ่าน cloud-init log:

Terminal window
ssh azureuser@<PUBLIC_IP> "tail -f /var/log/cloud-init-progress.log"

ขั้นตอนที่คาดหวัง: [init], [nic] (การตรวจจับ NIC แบบไดนามิก), [complete]

หาก cloud-init รายงานข้อผิดพลาด:

Terminal window
ssh azureuser@<PUBLIC_IP> "sudo cloud-init status --long"

รันวงจรคำขอเต็มรูปแบบและตรวจสอบห่วงโซ่การตอบสนอง:

Terminal window
# 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

ตรวจสอบว่า CDN vendor header ทั้งหมดถูกแทรกเข้ามาโดยการร้องขอ path /headers (เมื่อใช้ httpbin.org เป็นต้นทาง):

Terminal window
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 การตรวจจับอุปกรณ์เปลี่ยนแปลง:

Terminal window
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",
Terminal window
ssh azureuser@<PUBLIC_IP>
sudo systemctl status nginx
sudo journalctl -u nginx --no-pager -n 50

หลังจาก terraform apply cloud-init ใช้เวลา 2-3 นาที ตรวจสอบความคืบหน้า:

Terminal window
ssh azureuser@<PUBLIC_IP>
sudo cloud-init status
sudo tail -f /var/log/cloud-init-output.log
  • ตรวจสอบว่าต้นทางส่งคืนรหัสตอบสนองที่สามารถแคชได้ (200, 301, 302)
  • ตรวจสอบว่าต้นทางไม่ส่ง header Cache-Control: no-cache หรือ no-store
  • ตรวจสอบ NGINX error logs: sudo tail -f /var/log/nginx/error.log
  • ตรวจสอบว่ากฎ 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"