溫馨提示×

Ubuntu Apache如何優化圖片加載速度

小樊
47
2025-08-08 00:04:02
欄目: 智能運維

在Ubuntu上優化Apache服務器的圖片加載速度,可從以下方面入手:

  1. 啟用壓縮:使用mod_deflate模塊壓縮圖片,減少傳輸體積。

    sudo a2enmod deflate
    

    在配置文件中添加:

    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE image/jpeg image/png image/gif
    </IfModule>
    

    重啟Apache:sudo systemctl restart apache2。

  2. 設置緩存策略:通過mod_expires模塊延長圖片緩存時間。

    sudo a2enmod expires
    

    配置文件中添加:

    <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 image/gif "access plus 1 year"
    </IfModule>
    

    重啟Apache。

  3. 啟用HTTP/2:提升傳輸效率(需服務器支持)。

    sudo a2enmod http2
    

    配置文件中添加:

    Protocols h2 http/1.1
    

    重啟Apache。

  4. 優化圖片本身:使用工具(如imagemin)壓縮圖片大小,或轉換為更高效的格式(如WebP)。

  5. 使用CDN:將圖片托管到CDN,利用全球節點加速訪問。

  6. 啟用KeepAlive:減少TCP連接開銷。
    編輯配置文件:

    KeepAlive On
    MaxKeepAliveRequests 100
    KeepAliveTimeout 5
    

    重啟Apache。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女