【发布时间】:2019-11-06 06:04:37
【问题描述】:
我正在尝试使用Apache 2.4.39 (Amazon) 为Python 2.7 和Django 1.11 启用gzip 压缩。
我在创建Elastic Beanstalk php 7.2 应用程序时成功启用了gzip 压缩。
我将.htaccess文件放在/etc/httpd/conf.d中并命名为compression.conf
我重启了Apache
$ sudo service httpd restart
我的 test.html 页面使用了本地 js 和 css 文件,这些文件现在使用 gzip 压缩。
该文件来自html5 样板的压缩部分。
但是,Elastic Beanstalk、Python 2.7 和 Django 1.11 失败了。
我把文件放在这里/etc/httpd/conf.d/compression.conf
重启阿帕奇
本地 css 和 js 文件未压缩。
/var/log/httpd/error_log没有相关错误
欢迎提出任何建议。
==================================
.ebextensions 中的两个文件
来自 html5boilerplate .htaccess 文件
<----------------- start enable_mod_deflate.conf ------------------------->
# ----------------------------------------------------------------------
# | Compression |
# ----------------------------------------------------------------------
<IfModule mod_deflate.c>
# Force compression for mangled `Accept-Encoding` request headers
#
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding
# https://calendar.perfplanet.com/2010/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 media types.
#
# https://httpd.apache.org/docs/current/mod/mod_filter.html#addoutputfilterbytype
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE "application/atom+xml" \
"application/javascript" \
"application/json" \
"application/ld+json" \
"application/manifest+json" \
"application/rdf+xml" \
"application/rss+xml" \
"application/schema+json" \
"application/geo+json" \
"application/vnd.ms-fontobject" \
"application/wasm" \
"application/x-font-ttf" \
"application/x-javascript" \
"application/x-web-app-manifest+json" \
"application/xhtml+xml" \
"application/xml" \
"font/eot" \
"font/opentype" \
"font/otf" \
"image/bmp" \
"image/svg+xml" \
"image/vnd.microsoft.icon" \
"text/cache-manifest" \
"text/calendar" \
"text/css" \
"text/html" \
"text/javascript" \
"text/plain" \
"text/markdown" \
"text/vcard" \
"text/vnd.rim.location.xloc" \
"text/vtt" \
"text/x-component" \
"text/x-cross-domain-policy" \
"text/xml"
</IfModule>
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# Map the following filename extensions to the specified
# encoding type in order to make Apache serve the file types
# with the appropriate `Content-Encoding` response header
# (do note that this will NOT make Apache compress them!).
#
# If these files types would be served without an appropriate
# `Content-Enable` response header, client applications (e.g.:
# browsers) wouldn't know that they first need to uncompress
# the response, and thus, wouldn't be able to understand the
# content.
#
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
# https://httpd.apache.org/docs/current/mod/mod_mime.html#addencoding
<IfModule mod_mime.c>
AddEncoding gzip svgz
</IfModule>
</IfModule>
<--------------------------enable_mod_deflate.conf ------------------------------>
<---------------------- myapp.config ------------------------------------->
container_commands:
01_setup_apache:
command: "cp .ebextensions/enable_mod_deflate.conf /etc/httpd/conf.d/enable_mod_deflate.conf"
<---------------------- end myapp.config ------------------------------------->
基于: http://www.tonmoygoswami.com/2013/05/how-to-enable-gzip-on-amazon-elastic.html
【问题讨论】:
标签: python django apache gzip amazon-elastic-beanstalk