Skip to content

Zeroplex 生活隨筆

軟體開發、伺服器和生活瑣事

小 縮小字型大小。 中 重設字型大小。 大 放大字型大小。

gzip_types settings in Nginx

Posted on 2022 年 9 月 8 日2022 年 9 月 8 日 By 日落 在〈gzip_types settings in Nginx〉中尚無留言

以前一直誤會 gzip_types 可以使用 wildcrad * 來表示:

gzip on;
gzip_types text/* ;

事實上,上面的表達方式 Nginx 不吃,必須一條一條詳細列出來。

目前在 h5bp/server-configs-nginx 的建議中,建議需要 gzip 的設定如下:

gzip_types
  application/atom+xml
  application/geo+json
  application/javascript
  application/x-javascript
  application/json
  application/ld+json
  application/manifest+json
  application/rdf+xml
  application/rss+xml
  application/vnd.ms-fontobject
  application/wasm
  application/x-web-app-manifest+json
  application/xhtml+xml
  application/xml
  font/eot
  font/otf
  font/ttf
  image/bmp
  image/svg+xml
  image/vnd.microsoft.icon
  image/x-icon
  text/cache-manifest
  text/calendar
  text/css
  text/javascript
  text/markdown
  text/plain
  text/xml
  text/vcard
  text/vnd.rim.location.xloc
  text/vtt
  text/x-component
  text/x-cross-domain-policy;

另外,Chrome dev tool 要檢查檔案是否有壓縮,需要將滑鼠游標移動到檔案的 size 欄位,等到提示訊息出現時,比較 transfer size 和 resource size:

transfer-size-resource-size

若沒有 dev tool 的話,可以考慮參考 StackOverflow 這篇用 curl 比較 transfer / resource size:

curl --silent --write-out "%{size_download}\n" --output /dev/null https://my.domain/index.html

curl --silent -H "Accept-Encoding: gzip,deflate" --write-out "%{size_download}\n" --output /dev/null https://my.domain/index.html

若 Nginx 有正確做壓縮的話,二次顯示出來的 size 會不一樣,且第二個數值應該要比較小。

Tags:Nginx

文章導覽

Previous Post: Slimbook Battery – Linux 筆電電源管理工具
Next Post: 停用 Apport 錯誤回報功能

發佈留言 取消回覆

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *


其他

關於我  (About me)

小額贊助

  文章 RSS Feed

  留言 RSS Feed

Apache AWS Bash C/C++ Docker FreeBSD GCP Git Google Java JavaScript Laravel Linux Microsoft MSSQL MySQL Nginx PHP PHPUnit PostgreSQL Python Qt Ubuntu Unix Vim Web Windows WordPress XD 作業系統 分享 好站推薦 專題 攝影 新奇搞笑 新聞 旅遊 生活雜記 程式設計 網路架站 網頁設計 資訊學習 資訊安全 遊戲 音樂


創用 CC 授權條款
本著作係採用創用 CC 姓名標示-相同方式分享 4.0 國際 授權條款授權.