Is it possible to use AWS Beanstalk's .ebextensions config to install mod_pagespeed Apache module?

↘锁芯ラ 提交于 2019-12-30 01:15:41

问题


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.

  1. mod_deflate - You probably want to Gzip your html, css, xml, and javascript.
  2. Enable the rewrite domains filter in your Apache.conf if you use CDN (ex. AWS CloudFront)
  3. 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.
  4. 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.



来源:https://stackoverflow.com/questions/16066470/is-it-possible-to-use-aws-beanstalks-ebextensions-config-to-install-mod-pagesp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!