From 313aff19a139f1d14bfc73599f8789275cda23a9 Mon Sep 17 00:00:00 2001 From: Audrey Roy Greenfeld Date: Tue, 8 Nov 2016 09:50:51 -0800 Subject: [PATCH] Enable gzip compression on Elastic Beanstalk per @realpython https://realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/ --- .../.ebextensions/50_apache.config | 3 +++ .../.ebextensions/enable_mod_deflate.conf | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 {{cookiecutter.project_slug}}/.ebextensions/50_apache.config create mode 100644 {{cookiecutter.project_slug}}/.ebextensions/enable_mod_deflate.conf diff --git a/{{cookiecutter.project_slug}}/.ebextensions/50_apache.config b/{{cookiecutter.project_slug}}/.ebextensions/50_apache.config new file mode 100644 index 00000000..672cb625 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.ebextensions/50_apache.config @@ -0,0 +1,3 @@ +container_commands: + 01_setup_apache: + command: "cp .ebextensions/enable_mod_deflate.conf /etc/httpd/conf.d/enable_mod_deflate.conf" diff --git a/{{cookiecutter.project_slug}}/.ebextensions/enable_mod_deflate.conf b/{{cookiecutter.project_slug}}/.ebextensions/enable_mod_deflate.conf new file mode 100644 index 00000000..7a77cc23 --- /dev/null +++ b/{{cookiecutter.project_slug}}/.ebextensions/enable_mod_deflate.conf @@ -0,0 +1,25 @@ +# mod_deflate configuration + + # Restrict compression to these MIME types + AddOutputFilterByType DEFLATE text/plain + AddOutputFilterByType DEFLATE text/html + AddOutputFilterByType DEFLATE application/xhtml+xml + AddOutputFilterByType DEFLATE text/xml + AddOutputFilterByType DEFLATE application/xml + AddOutputFilterByType DEFLATE application/xml+rss + AddOutputFilterByType DEFLATE application/x-javascript + AddOutputFilterByType DEFLATE text/javascript + AddOutputFilterByType DEFLATE text/css + # Level of compression (Highest 9 - Lowest 1) + DeflateCompressionLevel 9 + # Netscape 4.x has some problems. + BrowserMatch ^Mozilla/4 gzip-only-text/html + # Netscape 4.06-4.08 have some more problems + BrowserMatch ^Mozilla/4\.0[678] no-gzip + # MSIE masquerades as Netscape, but it is fine + BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html + + # Make sure proxies don't deliver the wrong content + Header append Vary User-Agent env=!dont-vary + +