Installing and connecting the PageSpeed ​​module for NGINX in Centos 7

PageSpeed ​​is a module for the Apache and Nginx web server from Google, which is a set of filters that can significantly improve site performance.

Add the GetPageSpeed ​​repository

[[email protected]]# yum -y install

NGINX installation was covered earlier

Install the PageSpeed ​​module

[[email protected]]# yum -y install nginx-module-pagespeed

Let’s open the main NGINX config and connect the module

[[email protected]]# nano /etc/nginx/nginx.conf
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
load_module modules/;

We will connect the PageSpeer module in all our sites, for this we will create a file with the appropriate content

[[email protected]]# nano /etc/nginx/conf.d/pagespeed.conf
pagespeed on;
pagespeed FileCachePath /var/cache/pagespeed;
pagespeed HttpCacheCompressionLevel 0;

# HTTPS Support
pagespeed FetchHttps enable;

# PageSpeed Filters
# CSS Minification
pagespeed EnableFilters combine_css,rewrite_css;

# JS Minification
pagespeed EnableFilters combine_javascript,rewrite_javascript;

# Images Optimization
pagespeed EnableFilters lazyload_images;
pagespeed EnableFilters rewrite_images;
pagespeed EnableFilters convert_jpeg_to_progressive,convert_png_to_jpeg,convert_jpeg_to_webp,convert_to_webp_lossless;

# Remove comments from HTML
pagespeed EnableFilters remove_comments;

pagespeed EnableFilters collapse_whitespace;

A little about the parameter:

pagespeed HttpCacheCompressionLevel 0;

As it stands, the PageSpeed ​​module does not support internal Brotli compression. That is, you can still use it along with the Brotli NGINX module, but you will have to disable internal PageSpeed ​​compression via.

Checking the NGINX configuration for errors and reloading it

[[email protected]]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[[email protected]]# systemctl restart nginx