Last active
February 24, 2017 16:37
-
-
Save nuxero/fe83c24a979f2c1d3aaa8749764c6b65 to your computer and use it in GitHub Desktop.
ebextension for varnish cache + mod_pagespeed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
files: | |
"/etc/nginx/pagespeed.conf": | |
owner: root | |
group: root | |
mode: "000644" | |
content: | | |
pagespeed on; | |
# Needs to exist and be writable by nginx. Use tmpfs for best performance. | |
pagespeed FileCachePath /var/ngx_pagespeed_cache; | |
# Ensure requests for pagespeed optimized resources go to the pagespeed handler | |
# and no extraneous headers get set. | |
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { | |
add_header "" ""; | |
} | |
location ~ "^/pagespeed_static/" { } | |
location ~ "^/ngx_pagespeed_beacon$" { } | |
pagespeed RewriteLevel CoreFilters; | |
"/etc/varnish/default.vcl": | |
owner: root | |
group: root | |
mode: "000644" | |
content: | | |
backend default { | |
.host = "127.0.0.1"; | |
.port = "8082"; | |
} | |
sub vcl_recv { | |
if (req.url ~ "(time_nocache|other)"){ | |
return(pass); | |
} | |
} | |
sub vcl_fetch { | |
if (beresp.ttl < 60s) { | |
set beresp.ttl = 60s; | |
} | |
} | |
sub vcl_deliver { | |
if (obj.hits > 0) { | |
set resp.http.X-Cache = "HIT"; | |
} else { | |
set resp.http.X-Cache = "MISS"; | |
} | |
} | |
"/tmp/45_nginx_pagespeed.sh": | |
owner: root | |
group: root | |
mode: "000644" | |
content: | | |
#! /bin/bash | |
CONFIGURED=`grep -c "include /etc/nginx/pagespeed.conf" /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf` | |
if [ $CONFIGURED = 0 ] | |
then | |
sed -i '/listen 8080;/a \ include /etc/nginx/pagespeed.conf;\n' /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf | |
sed -i 's/listen 8080/listen 8082/' /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf | |
sed -i 's/VARNISH_LISTEN_PORT=6081/VARNISH_LISTEN_PORT=8080/' /etc/sysconfig/varnish | |
logger -t nginx_pagespeed "varnish caching and pagespeed rules added" | |
exit 0 | |
else | |
logger -t nginx_pagespeed "varnish caching and pagespeed rules already set" | |
exit 0 | |
fi | |
container_commands: | |
00_appdeploy_rewrite_hook: | |
command: cp -v /tmp/45_nginx_pagespeed.sh /opt/elasticbeanstalk/hooks/appdeploy/enact | |
01_configdeploy_rewrite_hook: | |
command: cp -v /tmp/45_nginx_pagespeed.sh /opt/elasticbeanstalk/hooks/configdeploy/enact | |
02_rewrite_hook_perms: | |
command: chmod 755 /opt/elasticbeanstalk/hooks/appdeploy/enact/45_nginx_pagespeed.sh /opt/elasticbeanstalk/hooks/configdeploy/enact/45_nginx_pagespeed.sh | |
03_rewrite_hook_ownership: | |
command: chown root:users /opt/elasticbeanstalk/hooks/appdeploy/enact/45_nginx_pagespeed.sh /opt/elasticbeanstalk/hooks/configdeploy/enact/45_nginx_pagespeed.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment