【发布时间】:2017-05-04 02:39:45
【问题描述】:
我有一个 Rails 应用程序,所以当我预编译时,gzip 资源也会为我编译。我使用以下 Apache 配置来提供 gzip 资产:
<Location /assets/>
RewriteEngine on
# Make sure the browser supports gzip encoding before we send it
# without it, Content-Type will be "application/x-gzip"
RewriteCond %{HTTP:Accept-Encoding} \b(x-)?gzip\b
RewriteCond %{REQUEST_FILENAME}.gz -s
RewriteRule ^(.+) $1.gz [L]
</Location>
# Also add a content-encoding header to tell the browser to decompress
<FilesMatch \.css\.gz$>
ForceType text/css
Header set Content-Encoding gzip
</FilesMatch>
<FilesMatch \.js\.gz$>
ForceType text/javascript
Header set Content-Encoding gzip
</FilesMatch>
但是,我注意到这在https SSL 站点上不起作用。它确实适用于http 网站。如何让 Apache 在https 上提供 gzip 资产?我不需要使用mod_deflate,因为当我编译我的 Rails 资产时,我的 gzipped 资产已经编译好了。
【问题讨论】:
-
这个配置在哪里?我怀疑你有 2 个不同的虚拟主机 SSL 和非 SSL,这仅适用于非 SSL 的。
-
哦,这可能只适用于非 SSL 的。此配置位于
<VirtualHost *:80>。我也应该把它复制到<VirtualHost _default_:443>吗? -
啊,这就是问题所在。我已将配置复制到 443 虚拟主机,它可以工作。谢谢!
标签: ruby-on-rails apache ssl gzip