Plesk

How to enable or disable the Google PageSpeed module in Nginx for a domain in Plesk?

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

  1. Connect to a Plesk server via SSH

  2. Enable the Google PageSpeed module for nginx:

    # plesk sbin nginx_modules_ctl -e pagespeed

  3. 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/

  4. Log in to Plesk

  5. Go to Domains > example.com > Apache and nginx settings

  6. 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 cache

    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$" { }

  7. 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

  1. Connect to the server via SSH

  2. Find the domains with PageSpeed enabled:

    # grep -l pagespeed /var/www/vhosts/system/*/conf/vhost_nginx.conf | cut -d '/' -f6

  3. Log in to Plesk

  4. For every domain found in step 2 go to Domains > example.com > Apache and nginx settings

  5. 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$" { }

  6. Over SSH disable the Google PageSpeed module for nginx:

    # plesk sbin nginx_modules_ctl -d pagespeed

  7. Optionally, remove the cached files for each domain:

    # rm -rf /var/cache/nginx_example_com/

Related Articles