I'm using AWS Beanstalk for my Django/Python application, and I would like to use Google's mod_pagespeed module. Is it possible to install and run mod_pagespeed using the .ebextensions/.config file?
问题:
回答1:
Download the package
Add the rpm into your ebextensions directory
create a .config file in the .ebextensions directory
add commands to the config file like this:
container_commands:
01-command:
command: rm -rf /pagespeed/ebextensions
02-command:
command: mkdir -p /pagespeed/ebextensions
03-command:
command: cp -R .ebextensions/* /pagespeed/ebextensions/
04-command:
command: rpm -U /pagespeed/ebextensions/mod-pagespeed.rpm
Ensure the commands are indented as shown, with no tabs, otherwise it wont work.
swap "mod-pagespeed.rpm" for whatever the actual rpm file name is.
回答2:
Ok so I want to add Charlie Smith's answer. I would suggest you make sure you have the following things turned on.
- mod_deflate - You probably want to Gzip your html, css, xml, and javascript.
- Enable the rewrite domains filter in your Apache.conf if you use CDN (ex. AWS CloudFront)
- Set a short cache-control for images and css so pagespeed will be able to extend the cache when you turn on the extend_cache filter.
- I also like the rewrite_javascript, dns_prefetch, collapse_whitespace, and combine_javascript filters.
Here are the GitHub Gists that show you how its done.
- The apache conf file
- The Beanstalk container_commands (they are mostly the same as Charlie's)
回答3:
Thanks guys! I got it working great following your answer @man2xxl.
You don't have to mess with the /pagespeed/extensions directory though, the beanstalk .ebextensions config can simply be:
packages:
yum:
at: []
10_setup_apache_for_mod_pagespeed:
command: "cp enable_mod_pagespeed.conf /etc/httpd/conf.d"
20_install_mod_pagespeed:
command: rpm -U -iv --replacepkgs mod-pagespeed-*.rpm
30_clear_mod_pagespeed_cache:
command: touch /var/cache/mod_pagespeed/cache.flush
回答4:
You can install packages by URL. So you don't have to download and distribute the RPM. Something like this works:
packages:
rpm:
pagespeed: https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm
files:
"/etc/httpd/conf.d/zzzz-pagespeed-options.conf":
mode: "00644"
owner: root
group: root
encoding: plain
content: |
# put your pagespeed configuration here
Note that I titled the file zzzz-pagespeed-options.conf so that the httpd server will load it last.
Another advantage of this is you really don't need include any commands whatsoever or worry about copying files over and maintaining the files in your .ebextensions folder. You just update the files entry in the .config file.