2021/05/09

XAMPP之Apache的deflate

摘要

本文概要介紹XAMPP裡的Apache伺服器啟用deflate模組以進行壓縮編碼的注意事項。

本文

Apache的deflate模組可以對內容進行gzip壓縮編碼,以縮小欲傳輸的內容。

欲啟用XAMPP裡的Apache伺服器的deflate,僅需在組態設定檔(C:\xampp\apache\conf\httpd.conf)將相關功能模組予以啟用。

LoadModule deflate_module modules/mod_deflate.so
LoadModule filter_module modules/mod_filter.so

接著再對相同的組態設定檔的末端,指明特定路徑(例如C:/xampp/htdocs)的特定型態(例如text/html)需要進行壓縮編碼即可。

SetOutputFilter DEFLATE
<Directory "C:/xampp/htdocs">
    <IfModule mod_deflate.c>
        AddOutputFilterByType DEFLATE text/html
    </IfModule>
</Directory>

使用不同的web客戶端程式對未啟用及已啟用deflate模組的Apache進行測試的結果截圖如下。

Firefox (with Accept-Encoding)→Apache with deflate-disabled

cURL without Accept-Encoding→Apache with deflate-disabled

cURL with Accept-Encoding→Apache with deflate-disabled

Firefox (with Accept-Encoding)→Apache with deflate-enabled
cURL without Accept-Encoding→Apache with deflate-enabled
cURL with Accept-Encoding→Apache with deflate-enabled

測試結果小結如下。

伺服端設定客戶端狀態gzip編碼
Apache w/ deflate-disabledFirefox (w/ Accept-Encoding)內容gzip編碼
Apache w/ deflate-disabledcURL w/o Accept-Encoding內容gzip編碼
Apache w/ deflate-disabledcURL w/ Accept-Encoding內容gzip編碼
Apache w/ deflate-enabledFirefox (w/ Accept-Encoding)內容具備gzip編碼
Apache w/ deflate-enabledcURL w/o Accept-Encoding內容gzip編碼
Apache w/ deflate-enabledcURL w/ Accept-Encoding內容具備gzip編碼


參考文獻

https://stackoverflow.com/questions/6993320/how-to-enable-gzip-compression-in-xampp-server/20472302
https://stackoverflow.com/questions/18983719/is-there-any-way-to-get-curl-to-decompress-a-response-without-sending-the-accept


沒有留言:

張貼留言