【问题标题】:Leverage browser caching on Amazon EC2利用 Amazon EC2 上的浏览​​器缓存
【发布时间】:2016-12-06 09:19:36
【问题描述】:

这是我第一次使用 Amazon AWS 进行任何托管,我在下面上传了我常用的代码,以帮助浏览器缓存,但 GT Metrix 和 Google Page speed 等工具似乎无法正常工作。

<IfModule mod_expires.c>
  ExpiresActive On
  ExpiresByType image/jpg "access plus 1 year"
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType application/pdf "access plus 1 month"
  ExpiresByType text/x-javascript "access plus 1 month"
  ExpiresByType application/x-shockwave-flash "access plus 1 month"
  ExpiresByType image/x-icon "access plus 1 year"
  ExpiresDefault "access plus 2 days"
</IfModule>

如果我需要在亚马逊方面启用任何功能以使其正常工作,有什么想法吗?

提前致谢。

【问题讨论】:

  • AWS EC2 只是一个普通的虚拟服务器。如果您直接在 EC2 中托管应用程序,您需要像在任何其他托管中一样配置缓存。但是,如果您在 EC2 前面使用 AWS Cloudfront 进行缓存,则需要在此处正确配置它。
  • 任何解决此问题的方法都将遭​​受同样的命运
  • 啊,是的!现在将添加我的解决方案

标签: apache .htaccess amazon-web-services amazon-ec2 pagespeed


【解决方案1】:

经过一番调查,结果发现我们的实例上没有安装所需的 Apache 模块。

你需要做的是以root用户ssh进入你的服务器并运行以下命令

使用此命令检查安装了哪些模块

apache2ctl -M

并寻找expires_module。它可能不存在。

启用浏览器缓存

sudo a2enmod expires

重启 apache

sudo service apache2 restart

【讨论】:

猜你喜欢
  • 2014-02-23
  • 2011-10-15
  • 2014-07-18
  • 1970-01-01
  • 2016-03-13
  • 2017-09-05
相关资源
最近更新 更多