跳到內容

與來源伺服器整合

本頁涵蓋兩個整合階段:

  1. 直接整合 — CDN 邊緣直接轉送至來源伺服器(基準測試)
  2. F5 XC 插入 — F5 XC HTTP 負載平衡器插入 CDN 與來源之間(安全示範)

先從直接整合開始建立基準,準備就緒後再插入 F5 XC。

origin-server 實驗室元件提供用於安全測試的易受攻擊網頁應用程式。

屬性
文件f5-sales-demo.github.io/origin-server
儲存庫github.com/f5-sales-demo/origin-server
預設連接埠80
健康檢查GET /health

從來源伺服器已發布的清單取得目前應用程式目錄:

Terminal window
MANIFEST_URL=$(curl -sf https://api.github.com/repos/f5-sales-demo/origin-server/releases/latest \
| python3 -c "import sys,json; assets=json.load(sys.stdin).get('assets',[]); print(next((a['browser_download_url'] for a in assets if a['name']=='manifest.json'),''))")
curl -sf "$MANIFEST_URL" | python3 -m json.tool

若尚未存在任何發行版,請直接使用儲存庫來源:

Terminal window
curl -sf https://raw.githubusercontent.com/f5-sales-demo/origin-server/main/manifest.json | python3 -m json.tool

清單列出所有應用程式路徑、健康檢查、容器映像檔及示範功能對應。

路徑應用程式示範功能
/首頁
/health健康檢查
/juice-shop/OWASP Juice ShopWAF、Bot 防禦、API 安全
/dvwa/DVWAWAF、Bot 防禦
/vampi/VAmPIAPI 安全
/httpbin/httpbin診斷
/whoami/whoami標頭驗證
/csd-demo/CSD Demo用戶端防禦
┌──────────┐ ┌──────────────────────┐ ┌─────────────────────┐
│ Client │────▶│ CDN Edge (NGINX) │────▶│ Origin Server │
│ │ │ 20.65.90.112 │ │ 20.12.78.159 │
└──────────┘ │ 67+ CDN headers │ │ Juice Shop, DVWA, │
│ Disk cache │ │ VAmPI, httpbin, │
└──────────────────────┘ │ whoami, CSD Demo │
└─────────────────────┘

在 CDN 邊緣 NGINX 設定中設定來源伺服器 IP:

Terminal window
ssh azureuser@<CDN_EDGE_IP>
sudo sed -i 's|proxy_pass .*;|proxy_pass http://<ORIGIN_IP>;|' /etc/nginx/conf.d/cdn-edge.conf
sudo rm -rf /var/cache/nginx/cdn/*
sudo nginx -t && sudo systemctl reload nginx

或在 Terraform 部署時透過 terraform.tfvars 設定:

origin_server = "http://<ORIGIN_IP>"

透過 CDN 測試各個來源應用程式:

Terminal window
CDN=<CDN_EDGE_IP>
# 健康檢查(CDN 本地)
curl -sf "http://$CDN/health" | python3 -m json.tool
# 首頁
curl -sf -o /dev/null -w "/ : HTTP %{http_code}\n" "http://$CDN/"
# Juice Shop
curl -sf -o /dev/null -w "/juice-shop/ : HTTP %{http_code}\n" "http://$CDN/juice-shop/"
# DVWA(跟隨重新導向至登入頁)
curl -sf -o /dev/null -w "/dvwa/ : HTTP %{http_code}\n" -L "http://$CDN/dvwa/"
# VAmPI API
curl -sf "http://$CDN/vampi/users/v1" | python3 -m json.tool | head -5
# httpbin 標頭(以 JSON 顯示 CDN 標頭)
curl -sf "http://$CDN/httpbin/headers" | python3 -m json.tool | head -10
# whoami(顯示來源接收到的所有標頭)
curl -sf "http://$CDN/whoami/"
# CSD Demo
curl -sf -o /dev/null -w "/csd-demo/ : HTTP %{http_code}\n" "http://$CDN/csd-demo/"

所有路徑應回傳 HTTP 200(DVWA 先回傳 302,跟隨後回傳 200)。

/whoami/ 端點顯示來源接收到的每一個標頭。透過 CDN 存取時,會顯示所有 67 個以上的廠商標頭:

Terminal window
curl -sf "http://$CDN/whoami/"

驗證以下關鍵標頭是否存在:

廠商標頭預期值
標準X-Forwarded-For<your_ip>, <cdn_edge_ip>
AkamaiTrue-Client-Ip<your_ip>
CloudflareCf-Connecting-Ip<your_ip>
CloudFrontCloudfront-Viewer-CountryUS
FastlyFastly-Client-Ip<your_ip>
Azure FDX-Azure-Clientip<your_ip>

比較兩台伺服器的存取日誌以驗證流量路徑:

Terminal window
# CDN 邊緣日誌 — 顯示您的用戶端 IP 為來源
ssh azureuser@<CDN_EDGE_IP> "sudo tail -5 /var/log/nginx/access.log"
# 來源日誌 — 顯示 CDN 邊緣 IP 為來源
ssh azureuser@<ORIGIN_IP> "sudo tail -5 /var/log/nginx/access.log"

來源日誌應顯示 CDN 邊緣 IP 為連線用戶端,而真實用戶端 IP 則由 X-Forwarded-For 及廠商專屬標頭傳遞。

Terminal window
# 第一次請求 — MISS(從來源取得)
curl -s -I "http://$CDN/whoami/" | grep X-Cache-Status
# 第二次請求 — HIT(由 CDN 快取提供)
curl -s -I "http://$CDN/whoami/" | grep X-Cache-Status

階段二:F5 XC 插入(安全示範)

Section titled “階段二:F5 XC 插入(安全示範)”

完成基準測試後,在 CDN 與來源之間插入 F5 XC HTTP 負載平衡器:

┌──────────┐ ┌────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Client │────▶│ CDN Edge │────▶│ F5 XC HTTP LB │────▶│ Origin Server │
│ │ │ (NGINX) │ │ WAF + Bot + API │ │ │
└──────────┘ └────────────────┘ └──────────────────┘ └─────────────────┘
  1. 建立 F5 XC HTTP 負載平衡器,並將來源伺服器加入其來源集區
  2. 更新 CDN 邊緣,使其指向 F5 XC VIP 而非直接指向來源:
Terminal window
ssh azureuser@<CDN_EDGE_IP>
sudo sed -i 's|proxy_pass .*;|proxy_pass https://<F5XC_LB_VIP>;|' /etc/nginx/conf.d/cdn-edge.conf
sudo rm -rf /var/cache/nginx/cdn/*
sudo nginx -t && sudo systemctl reload nginx
  1. 透過完整鏈路驗證 WAF 強制執行
Terminal window
# SQL 注入透過 CDN → F5 XC WAF 應予封鎖
curl -I "http://$CDN/dvwa/vulnerabilities/sqli/?id=%27+OR+1%3D1--"
# 正常請求應可通過
curl -sf -o /dev/null -w "%{http_code}" "http://$CDN/juice-shop/"
  1. 在 F5 XC 中設定受信任用戶端 IP 標頭,以從 CDN 標頭讀取真實用戶端 IP(例如 Akamai 模擬使用 True-Client-IP,Cloudflare 模擬使用 CF-Connecting-IP
元件儲存庫用途
CDN 邊緣(本項)cdn-simulator快取、廠商標頭
來源伺服器origin-server易受攻擊的網頁應用程式
F5 XC 設定各種(waf、api-protection、bot-* 等)安全政策

每個元件均發布 AI 助理用於部署基礎設施的文件。來源伺服器以 GitHub Release 成品形式發布端點清單,列出所有應用程式路徑與健康檢查。