【问题标题】:Serving gzip assets over HTTPS/SSL with Apache使用 Apache 通过 HTTPS/SSL 提供 gzip 资产
【发布时间】: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 的。此配置位于&lt;VirtualHost *:80&gt;。我也应该把它复制到&lt;VirtualHost _default_:443&gt;吗?
  • 啊,这就是问题所在。我已将配置复制到 443 虚拟主机,它可以工作。谢谢!

标签: ruby-on-rails apache ssl gzip


【解决方案1】:

正如 cmets 中提到的@Capsule,除了&lt;VirtualHost *:80&gt; 之外,我还需要将gzip 配置块放入&lt;VirtualHost _default_:443&gt;

【讨论】:

  • 我会把它放在一个.htaccess 文件中,这样你就不会重复规则,如果可以的话。
  • 或者只是将非 SSL 重定向到 SSL 并且在 SSL vhost 中只有一个配置
猜你喜欢
  • 2012-03-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-06-28
  • 1970-01-01
  • 2015-03-25
  • 2018-04-02
相关资源
最近更新 更多