Skip to content
VirtuBox edited this page Jun 4, 2018 · 4 revisions

We use two files to set Pagespeed configuration with Nginx

Global rules

The first one is /etc/nginx/conf.d/pagespeed

# disable pagespeed to activate it on each vhost
pagespeed standby;

# admin panel path
pagespeed GlobalStatisticsPath /ngx_pagespeed_global_statistics;
pagespeed MessagesPath /ngx_pagespeed_message;
pagespeed ConsolePath /pagespeed_console;
pagespeed AdminPath /pagespeed_admin;
pagespeed GlobalAdminPath /pagespeed_global_admin;

# hide pagespeed version in header 
pagespeed XHeaderValue "ngx_pagespeed";

# cache path
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# cache with redis
pagespeed RedisServer "127.0.0.1:6379";
pagespeed RedisDatabaseIndex 2;

# Purge nginx pagespeed cache
# https://developers.google.com/speed/pagespeed/module/system#flush_cache
pagespeed EnableCachePurge on;
pagespeed PurgeMethod PURGE;

# statistics and logs
pagespeed Statistics on;
pagespeed StatisticsLogging on;
pagespeed LogDir /var/log/pagespeed;

vhost rules

The second one is /etc/nginx/common/pagespeed-vhost.conf.
Just add include common/pagespeed-vhost.conf; in your vhost to enable pagespeed rules listed below

# enable pagespeed
pagespeed on;
# 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$" { }

# Filter settings
# filters outlined at http://ngxpagespeed.com/ngx_pagespeed_example/
pagespeed RewriteLevel CoreFilters;
pagespeed EnableFilters collapse_whitespace,remove_comments;

# rewrite_images
# https://developers.google.com/speed/docs/mod_pagespeed/filter-image-optimize
pagespeed EnableFilters rewrite_images;

# inline_google_font_css
# https://developers.google.com/speed/pagespeed/module/filter-css-inline-google-fonts
pagespeed EnableFilters inline_google_font_css;

# Additional settings
pagespeed PreserveUrlRelativity on;
pagespeed MaxCombinedCssBytes -1;
pagespeed AvoidRenamingIntrospectiveJavascript on;

# protect admin panel with ACL
location /ngx_pagespeed_statistics { include common/acl.conf; }
location /ngx_pagespeed_global_statistics { include common/acl.conf; }
location /ngx_pagespeed_message { include common/acl.conf; }
location /pagespeed_console { include common/acl.conf; }
location ~ ^/pagespeed_admin { include common/acl.conf; }

Customizing Nginx compilation

Nginx Configuration :

Plesk Configuration :

Clone this wiki locally