Last active
November 4, 2022 15:24
-
-
Save nuxero/49dca3fdadfea82078c24407bde82714 to your computer and use it in GitHub Desktop.
ebextension config file for pagespeed and proxy cache on nginx
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/nginx/nocache.conf": | |
owner: root | |
group: root | |
mode: "000644" | |
content: | | |
set $no_cache 0; | |
if ($request_uri ~* "/(time_nocache|other)"){ | |
set $no_cache 1; | |
} | |
"/etc/nginx/cache.conf": | |
owner: root | |
group: root | |
mode: "000644" | |
content: | | |
proxy_cache MYAPP; | |
proxy_ignore_headers Cache-Control; | |
proxy_cache_valid any 1m; | |
proxy_cache_bypass $no_cache; | |
proxy_no_cache $no_cache; | |
add_header X-Cache-Status $upstream_cache_status; | |
"/etc/nginx/conf.d/proxycache.conf": | |
owner: root | |
group: root | |
mode: "000644" | |
content: | | |
proxy_cache_path /etc/nginx/cache levels=1:2 keys_zone=MYAPP:100m inactive=60m max_size=500m; | |
"/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 '/include \/etc\/nginx\/pagespeed.conf;/a \ include /etc/nginx/nocache.conf;\n' /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf | |
sed -i '/http:\/\/nodejs;/a \ include /etc/nginx/cache.conf;\n' /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf | |
logger -t nginx_pagespeed "caching and pagespeed rules added" | |
exit 0 | |
else | |
logger -t nginx_pagespeed "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