Skip to content

Instantly share code, notes, and snippets.

@secfigo
Last active July 20, 2017 15:11
Show Gist options
  • Save secfigo/f41a5f243610053d03ad410254540802 to your computer and use it in GitHub Desktop.
Save secfigo/f41a5f243610053d03ad410254540802 to your computer and use it in GitHub Desktop.
Google pagespeed insights - Performance Improvements
# Install essential build tools
sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip
#Install libs to compile nginx modules
sudo apt-get install libxslt1-dev libssl-dev libgd2-xpm-dev libgeoip-dev libpam-dev
#Install nginx ppa
sudo add-apt-repository ppa:nginx/stable
sudo apt-get update
sudo apt-get install nginx -y
# Compile dynamic pagespeed module for nginx, please note --dynamic at line 15.
bash <(curl -f -L -sS https://ngxpagespeed.com/install) \
--nginx-version "1.12.1" \
--dynamic \
-a '--with-cc-opt="-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2 -DNGX_HTTP_HEADERS" --with-ld-opt="-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now -fPIC" --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-stream_ssl_preread_module --with-mail=dynamic --with-mail_ssl_module'
#Copy ngx_pagespeed into nginx modules
sudo cp nginx-1.12.1/objs/ngx_pagespeed.so /usr/share/nginx/modules/
#Add the following into /etc/nginx/nginx.conf
load_module "modules/ngx_pagespeed.so";
# Enable pagespeed module by putting the following in http context
pagespeed on;
pagespeed Statistics on;
pagespeed StatisticsLogging on;
pagespeed LogDir /var/log/pagespeed;
# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;
pagespeed RespectVary on;
pagespeed LowercaseHtmlNames on;
# optional
pagespeed XHeaderValue "Powered By ngx_pagespeed";
# admin
# filter
pagespeed RewriteLevel PassThrough;
# image
pagespeed EnableFilters rewrite_images,responsive_images_zoom;
# css
pagespeed EnableFilters inline_import_to_link;
pagespeed EnableFilters outline_css;
pagespeed CssOutlineMinBytes 1000;
pagespeed EnableFilters combine_css,rewrite_css,rewrite_style_attributes,flatten_css_imports,prioritize_critical_css,sprite_images;
# js
pagespeed EnableFilters rewrite_javascript,combine_javascript;
pagespeed UseExperimentalJsMinifier on;
pagespeed EnableFilters remove_comments;
pagespeed EnableFilters collapse_whitespace;
pagespeed EnableFilters elide_attributes;
pagespeed EnableFilters extend_cache;
pagespeed EnableFilters trim_urls;
pagespeed EnableFilters local_storage_cache;
# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment