Skip to content

Instantly share code, notes, and snippets.

@janglapuk
Last active March 30, 2018 22:47
Show Gist options
  • Save janglapuk/71cf52a2e59bc48d5b7fb30ecbb41c39 to your computer and use it in GitHub Desktop.
Save janglapuk/71cf52a2e59bc48d5b7fb30ecbb41c39 to your computer and use it in GitHub Desktop.
A note to tweaks page speed with Nginx
- Rebuild Nginx with PageSpeed module
https://www.digitalocean.com/community/tutorials/how-to-add-ngx_pagespeed-to-nginx-on-debian-8
- Enable GZIP
#---------------------------------------------------------------#
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 4 32k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;
#---------------------------------------------------------------#
- Enable PageSpeed module
#---------------------------------------------------------------#
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
pagespeed RewriteLevel CoreFilters;
pagespeed EnableFilters prioritize_critical_css;
pagespeed EnableFilters defer_javascript;
pagespeed EnableFilters sprite_images;
pagespeed EnableFilters convert_png_to_jpeg,convert_jpeg_to_webp;
pagespeed EnableFilters collapse_whitespace,remove_comments;
pagespeed EnableFilters combine_css,extend_cache,rewrite_images;
pagespeed EnableFilters rewrite_css,rewrite_javascript;
#---------------------------------------------------------------#
- Modify /etc/nginx/sites-enabled/*, and add these lines at 'server' block:
#---------------------------------------------------------------#
# 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 ~ "^/ngx_pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon" { }
#---------------------------------------------------------------#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment