驗證
部署後,執行以下檢查以確認 CDN 邊緣節點正常運作。在 terraform apply 後請等待 2-3 分鐘,讓 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 輸出:
curl -s "$(terraform output -raw health_check_url)" | jq .快取未命中(第一次請求)
Section titled “快取未命中(第一次請求)”對任何路徑的第一次請求將會是快取未命中——邊緣節點會從來源擷取內容:
curl -I "http://<PUBLIC_IP>/"請在回應中尋找以下標頭:
X-Cache-Status: MISSX-CDN-Edge: cdn-simulatorMISS 表示內容不在快取中,已從來源伺服器擷取。
快取命中(後續請求)
Section titled “快取命中(後續請求)”立即重複相同的請求:
curl -I "http://<PUBLIC_IP>/"預期標頭:
X-Cache-Status: HITX-CDN-Edge: cdn-simulatorHIT 確認回應是從 NGINX 磁碟快取提供,未聯繫來源。
快取目錄檢查
Section titled “快取目錄檢查”SSH 進入虛擬機器以確認快取內容存在於磁碟上:
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/cdnNGINX 狀態
Section titled “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來源連線檢查
Section titled “來源連線檢查”確認邊緣節點能夠連接到來源伺服器:
ssh azureuser@<PUBLIC_IP>
# Test connectivity to origin (replace with your origin URL)curl -I "https://your-origin.example.com/"若此操作失敗,請檢查:
- Terraform 設定中的
origin_server變數是否正確 - 來源伺服器是否允許來自邊緣節點公用 IP 的輸入連線
- DNS 解析是否能從虛擬機器正常運作(
nslookup your-origin.example.com)
Cloud-Init 進度
Section titled “Cloud-Init 進度”透過 cloud-init 日誌監控佈建進度:
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供應商標頭驗證
Section titled “供應商標頭驗證”透過請求 /headers 路徑(使用 httpbin.org 作為來源時)確認所有 CDN 供應商標頭均已注入:
curl -s "http://<PUBLIC_IP>/headers" | python3 -m json.tool預期回應包含來自所有五個供應商的標頭:
{ "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" }}裝置偵測測試
Section titled “裝置偵測測試”使用行動裝置 User-Agent 進行測試,以確認裝置偵測標頭會發生變化:
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 未執行
Section titled “NGINX 未執行”ssh azureuser@<PUBLIC_IP>sudo systemctl status nginxsudo journalctl -u nginx --no-pager -n 50Cloud-init 尚未完成
Section titled “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
Section titled “快取持續顯示 MISS”- 確認來源回傳可快取的回應碼(200、301、302)
- 確認來源未傳送
Cache-Control: no-cache或no-store標頭 - 檢查 NGINX 錯誤日誌:
sudo tail -f /var/log/nginx/error.log
連接埠 80/443 拒絕連線
Section titled “連接埠 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"