Mise en place du module pagespeed

Préparation

  • Installer le paquet nginx-extra
  • Créer le dossier /var/ngx_pagespeed_cache pour y monter un tmpfs, 256Mo sont sufisant pour une instance wordpress
mkdir /var/ngx_pagespeed_cache
echo 'tmpfs /var/ngx_pagespeed_cache tmpfs defaults,size=256M 0 0' >> /etc/fstab
mount -a

Configuration pour votre “server” :

# enable ngx_pagespeed
pagespeed on;
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 ~ "^/ngx_pagespeed_/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
location /ngx_pagespeed_global_statistics { allow 127.0.0.1; deny all; }
location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }

pagespeed RewriteLevel CoreFilters;
pagespeed ModifyCachingHeaders off;
pagespeed EnableFilters canonicalize_javascript_libraries;
pagespeed EnableFilters collapse_whitespace;
pagespeed EnableFilters combine_css;
pagespeed EnableFilters combine_heads;
pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters elide_attributes;
pagespeed EnableFilters extend_cache;
pagespeed EnableFilters flatten_css_imports;
pagespeed EnableFilters insert_dns_prefetch;
pagespeed EnableFilters lazyload_images;
pagespeed EnableFilters make_google_analytics_async;
pagespeed EnableFilters remove_comments;
pagespeed EnableFilters rewrite_css,sprite_images;
pagespeed EnableFilters rewrite_images;
pagespeed EnableFilters rewrite_javascript;

Et voila, vous pouvez relancer nginx et regarder votre score https://developers.google.com/speed/pagespeed/insights/ 🙂

Documentation complète : https://developers.google.com/speed/pagespeed/module/configuration



comments powered by Disqus