Answers:
这需要deflate
模块,因此启用它。在Ubuntu(这是我正在使用的)下,该命令为a2enmod deflate
。
然后,SetOutputFilter
在您的Proxy
或Directory
指令上使用:
<ProxyMatch "^http://localhost:8080/($|app/)">
Order allow,deny
Allow from all
SetOutputFilter Deflate
</ProxyMatch>
要么:
<Directory /var/www>
Order allow,deny
Allow from all
SetOutputFilter Deflate
</Directory>
根据您的部署,将其作为mod_deflate.conf放置在conf.d或extras文件夹中:
# Enable mod_deflate (gzip)
SetOutputFilter DEFLATE
# Do not attempt to compress the following extensions
SetEnvIfNoCase Request_URI \
\.(?:gif|jpe?g|png|swf|flv|zip|gz|tar|mp3|mp4|m4v)$ no-gzip dont-vary
重新启动apache并且mod_deflate将出现在所有与上述正则表达式不匹配的扩展上,这减少了总体CPU开销,因为它阻止了mod_deflate尝试压缩几乎看不到压缩的格式(因为它已经被压缩)。
要查看压缩的确切内容和压缩率,请将其放置在
# Deflate accurate logging
DeflateFilterNote Input instream
DeflateFilterNote Output outstream
DeflateFilterNote Ratio ratio
LogFormat '"%r" %{outstream}n/%{instream}n (%{ratio}n%%)' deflate
CustomLog logs/yourdomain_deflate.log