Ubuntu Apache配置实现CDN加速
一、方案总览与选择
二、方案一 第三方CDN接入步骤
sudo a2enmod deflate expires headers<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript application/json
</IfModule>
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
</IfModule>
<IfModule mod_headers.c>
Header set Cache-Control "max-age=31536000, public"
</IfModule>
<IfModule mod_cache.c>
<IfModule mod_cache_disk.c>
CacheRoot /var/cache/apache2/mod_cache_disk
CacheEnable disk /static/
CacheDirLevels 2
CacheDirLength 1
</IfModule>
</IfModule>
sudo systemctl restart apache2。三、方案二 自建边缘缓存 Apache Traffic Server
sudo apt-get update && sudo apt-get install trafficserversudo systemctl start trafficserver四、验证与运维要点
curl -I https://yourdomain.com/static/logo.png,应见到CDN节点IP、Cache-Control/Expires、以及CF-Cache-Status/Hit等字段(以所用CDN为准)。