Question
How to enable or disable the Google PageSpeed module in Nginx for a domain in Plesk?
Answer
Warning: Due to a CentOS Kernel Bug, do not enable PageSpeed in nginx when SELinux is in enforcing mode
Enabling Google PageSpeed module
-
Connect to a Plesk server via SSH
-
Enable the Google PageSpeed module for nginx:
# plesk sbin nginx_modules_ctl -e pagespeed
-
Create a directory where nginx cache will be stored and adjust permissions and ownership:
# mkdir /var/cache/nginx_example_com/
# chown nginx:nginx /var/cache/nginx_example_com/
# chmod 700 /var/cache/nginx_example_com/ -
Go to Domains > example.com > Apache and nginx settings
-
Add the following lines into the Additional nginx directives and click OK to apply the changes:
Note: Replace
FileCachePath
with path created in Step 3 where the Nginx will store the cachepagespeed on;
pagespeed FileCachePath "/var/cache/nginx_example_com/";
pagespeed RewriteLevel OptimizeForBandwidth;
location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { } -
To verify that the module is enabled, run the command on the server directly:
# curl -Is https://example.com | grep X-Page-Speed
X-Page-Speed: 1.13.35.2-0
Disabling Google PageSpeed module
-
Connect to the server via SSH
-
Find the domains with PageSpeed enabled:
# grep -l pagespeed /var/www/vhosts/system/*/conf/vhost_nginx.conf | cut -d '/' -f6
-
For every domain found in step 2 go to Domains > example.com > Apache and nginx settings
-
Remove the following lines from Additional nginx directives and click OK to apply the changes:
pagespeed on;
pagespeed FileCachePath "/var/cache/nginx_example_com/";
pagespeed RewriteLevel OptimizeForBandwidth;
location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { } -
Over SSH disable the Google PageSpeed module for nginx:
# plesk sbin nginx_modules_ctl -d pagespeed
-
Optionally, remove the cached files for each domain:
# rm -rf /var/cache/nginx_example_com/