# httpd.conf 取消註釋
LoadModule expires_module modules/mod_expires.so
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 10 days"
# CSS/JS 快取 14 天
ExpiresByType text/css "access plus 14 days"
ExpiresByType text/javascript "access plus 14 days"
ExpiresByType application/javascript "access plus 14 days"
ExpiresByType application/x-javascript "access plus 14 days"
# 圖片/媒體快取 14 天
ExpiresByType image/jpeg "access plus 14 days"
ExpiresByType image/png "access plus 14 days"
ExpiresByType image/gif "access plus 14 days"
ExpiresByType image/webp "access plus 14 days"
ExpiresByType image/svg+xml "access plus 14 days"
ExpiresByType video/mp4 "access plus 14 days"
ExpiresByType audio/mpeg "access plus 14 days"
# 字體檔案
ExpiresByType font/woff "access plus 14 days"
ExpiresByType font/woff2 "access plus 14 days"
ExpiresByType application/font-woff2 "access plus 14 days"
# 特定副檔名強制長期快取
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault "access plus 1 year"
</FilesMatch>
# HTML 不快取或短快取(視業務調整)
ExpiresByType text/html "access plus 1 hour"
</IfModule>
| 語法 | 含義 |
|---|---|
access plus N days | 從存取時間起算 N 天 |
modification plus N days | 從檔案修改時間起算 |
A86400 | 秒數表示(86400=1天) |
M2592000 | 修改時間起算秒數 |
<IfModule mod_headers.c>
# 靜態資源添加公共快取標頭
<FilesMatch "\.(css|js|jpg|jpeg|png|gif|ico|woff|woff2)$">
Header set Cache-Control "public, max-age=1209600, immutable"
</FilesMatch>
# HTML 私有快取,需驗證
<FilesMatch "\.html$">
Header set Cache-Control "private, must-revalidate"
</FilesMatch>
</IfModule>
# curl 檢查回應標頭
curl -I https://example.com/style.css
# 預期看到:
# Cache-Control: max-age=1209600
# Expires: Wed, 15 Jan 2025 08:00:00 GMT
style.v202501.css) 可安心設長期快取?v=timestamp 強制刷新正確配置瀏覽器快取可減少 60-80% 重複請求,大幅降低伺服器頻寬與 CPU 壓力,提升首屏載入速度。
伺服器日誌清理實務:系統/安全/應用程式/FTP/IIS 日誌清除工具與技巧
Serv-U 歡迎訊息動態參數完全指南:打造專屬 FTP 登入體驗
IIS 7/7.5 啟用 32 位應用程式模式:解決 FastCGI 500 錯誤與 Access/Excel 連線失效
CDN 緩存更新與同步機制全解析:靈活的刷新策略保障內容實時性
防範 ASP 木馬在伺服器執行:封鎖高危 COM 元件與指令執行
vsftpd 快速部署進階版:Chroot 限制目錄、命令白名單與獨立守護進程模式
服務器 C 盤僅保留 Administrators 權限導致 ASP 組件失效:FSO、ADODB、MSXML 修復實錄