我已经通过 easyapache 4 在我的 WHM 服务器上安装了 mod_brotli - html、css、js 文件等都被压缩了。
然后我在官方文档中遇到了这个 - https://httpd.apache.org/docs/2.4/mod/mod_brotli.html#precompressed
此后,我将其添加到 WHM (post_virtualhost_global.conf) 中的 Post VirtualHost 包含文件中,而不是 htaccess,因为我希望它是服务器范围的。
如何验证这是否有效并且确实提供预压缩文件?无论哪种方式我都没有找到任何可说的,我只能确认 brotli 压缩正在使用中。无论是否包含包含,CPU 负载几乎相同,因此我怀疑它可能不会为下次保存压缩文件。
这是虚拟主机包括:
<IfModule mod_headers.c>
# Serve brotli compressed CSS and JS files if they exist
# and the client accepts brotli.
RewriteCond "%{HTTP:Accept-encoding}" "br"
RewriteCond "%{REQUEST_FILENAME}\.br" "-s"
RewriteRule "^(.*)\.(js|css)" "$1\.$2\.br" [QSA]
# Serve correct content types, and prevent double compression.
RewriteRule "\.css\.br$" "-" [T=text/css,E=no-brotli:1]
RewriteRule "\.js\.br$" "-" [T=text/javascript,E=no-brotli:1]
<FilesMatch "(\.js\.br|\.css\.br)$">
# Serve correct encoding type.
Header append Content-Encoding br
# Force proxies to cache brotli &
# non-brotli css/js files separately.
Header append Vary Accept-Encoding
</FilesMatch>
</IfModule>
这是我的 /etc/apache2/conf.2/brotli.conf
<IfModule brotli_module>
# Compress only a few types
# https://httpd.apache.org/docs/trunk/mod/mod_brotli.html
AddOutputFilterByType BROTLI_COMPRESS text/plain text/css text/html application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript
SetOutputFilter BROTLI_COMPRESS
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-brotli
BrotliFilterNote Input instream
BrotliFilterNote Output outstream
BrotliFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' brotli
CustomLog "logs/brotli_log" brotli
</IfModule>
这是/etc/apache2/conf.modules.d/115_mod_brotli.conf
# Enable mod_brotli
LoadModule brotli_module modules/mod_brotli.so
因此,如果有人可以帮助我弄清楚如何确认文件是否已预压缩,那就太好了。
编辑:我认为我的文件没有被预压缩。有人对此有任何进一步的信息吗?我在 akk 上找不到任何更多的帖子或文档