‹ Articles

How to Enable PageSpeed

Careful, don't break your server! This customization is not supported by ServerPilot.

You should first read the article on customizing Nginx.
ServerPilot can't provide support for configuring PageSpeed or debugging breakage it causes on your apps.

For support, you should use the PageSpeed discussion group.

Nginx on your server is built with Google's ngx_pagespeed extension. PageSpeed applies automatic optimizations to your websites and reduces page load time by applying web performance best practices to pages and assets (CSS, JavaScript, images) without requiring you to modify your website.

As using PageSpeed can break some websites and will consume a significant amount of memory, ServerPilot does not enable PageSpeed by default and cannot provide support for it.

Enable PageSpeed for an App

To enable PageSpeed, SSH in as root and create the file:


with the following content (replace APPNAME with the name of your app)

pagespeed on;
pagespeed FileCachePath /var/cache/pagespeed;

# 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$" { }
location /ngx_pagespeed_statistics { deny all; }
location /ngx_pagespeed_global_statistics { deny all; }
location /ngx_pagespeed_message { deny all; }
location /pagespeed_console { deny all; }

Then, restart Nginx by running the following command as root:

sudo service nginx-sp restart

You can verify PageSpeed is enabled by looking for the X-Page-Speed response header:

curl -s -I http://YOUR_DOMAIN/ | grep X-Page-Speed

You should see output that contains the following:

X-Page-Speed: ...

Still Have Questions?

Don't hesitate to contact us if you can't find the answers to your questions.