简体   繁体   English

Django-AWS gzip压缩未启用?

[英]Django-AWS gzip compression not enabled?

I followed this tutorial: https://realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/ to deploy my Django site to AWS. 我遵循了本教程: https : //realpython.com/blog/python/deploying-a-django-app-to-aws-elastic-beanstalk/将我的Django站点部署到AWS。 Everything works fine, but when I use Google's PageSpeed, it tells me that gzip is not enabled. 一切正常,但是当我使用Google的PageSpeed时,它告诉我未启用gzip。 Here are two files: 这是两个文件:

03_apache.config 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 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>

Those are located in .ebextensions and should be able to setup gzip. 这些文件位于.ebextensions中,应该能够设置gzip。 What am I doing wrong? 我究竟做错了什么?

Try to use NGINX instead of Apache. 尝试使用NGINX代替Apache。 Nginx came onto the scene after Apache, with more awareness of the concurrency problems that would face sites at scale. Nginx在Apache之后问世,对并发问题有更多的了解,这些并发问题将在大规模站点上出现。 Leveraging this knowledge, Nginx was designed from the ground up to use an asynchronous, non-blocking, event-driven connection handling algorithm. 利用这些知识,Nginx从头开始设计为使用异步,非阻塞,事件驱动的连接处理算法。

NGINX Configuration are comfortable to use than Apache. NGINX Configuration比Apache更易于使用。

For gzip compression follow this link. 对于gzip压缩,请点击此链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM