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

前端 未结 4 531
执念已碎
执念已碎 2020-12-29 12:43

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

相关标签:
4条回答
  • 2020-12-29 13:29

    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)
    0 讨论(0)
  • 2020-12-29 13:33

    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
    
    0 讨论(0)
  • 2020-12-29 13:35

    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.

    0 讨论(0)
  • 2020-12-29 13:46

    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.

    0 讨论(0)
提交回复
热议问题