【问题标题】:Django-AWS gzip compression not enabled?未启用 Django-AWS gzip 压缩?
【发布时间】:2015-10-08 16:59:33
【问题描述】:

我按照本教程:https://realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/ 将我的 Django 站点部署到 AWS。一切正常,但是当我使用 Google 的 PageSpeed 时,它告诉我 gzip 未启用。这里有两个文件:

03_apache.config

container_commands:
  01_setup_apache:
    command: "cp .ebextensions/enable_mod_deflate.conf /etc/httpd/conf.d/enable_mod_deflate.conf"

enable_mod_deflate.conf

# mod_deflate configuration
<IfModule mod_deflate.c>
  # 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
<IfModule mod_headers.c>
  # Make sure proxies don't deliver the wrong content
  Header append Vary User-Agent env=!dont-vary
</IfModule>
</IfModule>

它们位于 .ebextensions 中,应该能够设置 gzip。我做错了什么?

【问题讨论】:

    标签: python django apache amazon-web-services gzip


    【解决方案1】:

    尝试使用 NGINX 而不是 Apache。 Nginx 是在 Apache 之后出现的,对大规模站点将面临的并发问题有了更多的认识。利用这些知识,Nginx 从一开始就被设计为使用异步、非阻塞、事件驱动的连接处理算法。

    NGINX 配置比 Apache 使用起来更舒服。

    对于 gzip 压缩,请遵循 link.

    【讨论】: