如何在Heroku上的PHP应用程序中启用压缩?

9
我将在Heroku应用程序上的.htaccess文件中运行HTML5 Boilerplate压缩。但是,似乎没有起作用,没有任何文件被压缩。
我已经添加了Heroku PHP构建包:
heroku config:set BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-php

但这似乎没有起到任何作用。我对Heroku还比较陌生,所以有人有什么建议吗?

HTML5 Boilerplate htaccess代码:

# Force compression for mangled headers.
# http://developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping
<IfModule mod_setenvif.c>
    <IfModule mod_headers.c>
        SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
        RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
    </IfModule>
</IfModule>

# Compress all output labeled with one of the following MIME-types
# (for Apache versions below 2.3.7, you don't need to enable `mod_filter`
#  and can remove the `<IfModule mod_filter.c>` and `</IfModule>` lines
#  as `AddOutputFilterByType` is still in the core directives).
<IfModule mod_filter.c>
    AddOutputFilterByType DEFLATE application/atom+xml \
                                  application/javascript \
                                  application/json \
                                  application/rss+xml \
                                  application/vnd.ms-fontobject \
                                  application/x-font-ttf \
                                  application/x-web-app-manifest+json \
                                  application/xhtml+xml \
                                  application/xml \
                                  font/opentype \
                                  image/svg+xml \
                                  image/x-icon \
                                  text/css \
                                  text/html \
                                  text/plain \
                                  text/x-component \
                                  text/xml
</IfModule>


他已经尝试了他的服务器。 - jacouh
1个回答

4
我发现使用不同的构建包成功了!
heroku config:set BUILDPACK_URL=http://github.com/iphoting/heroku-buildpack-php-tyler

这是一个很棒的构建包,可以启用gzip压缩并安装new-relic。


对我来说,它显示了一个错误:"stdin:不是gzip格式"。我应该在Heroku上安装一些插件才能工作吗? - rodrigorf
仍然在这里遇到相同的错误 @EzraObiwale,目前还没有解决方案。 - rodrigorf

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接