Installing Pagespeed module on nginx as dynamic module
first you need to compile the module on same os like ubuntu 18.04 & same nginx version nginx 13
To know version of os & nginx
You can run this commands
nginx -v
//It shows current version of nginx
to know linux distribution version
lsab- v
//
installing
risky: you can also compile & install it on a live server.
just like upgrading nginx in live server. Just we need restart / reload.
if any errors we can solve it by nginx error log.
Remove / rename old compiled module
from
mv objs/ngx_pagespeed.so objs/ngx_pagespeed13.9so
mv /etc/nginx/modules/ngx_pagespeed.so /etc/nginx/modules/ngx_pagespeed13.9.so
Install devtools
sudo apt-get install unzip gcc make libpcre3-dev zlib1g-dev
strongly recommend that you compile dynamic modules on a separate system, which we refer to here as the “build environment
same os and same nginx.
compiling Pagespeed module with latest nginx
check version
nginx -v
nginx version: nginx/1.15.2
Download the same version of nginx to compile already covered above.
create directory
mkdir -p /etc/new/nginx/
cd /etc/new/nginx/
download latest nginx
wget -qO – http://nginx.org/download/nginx-1.15.2.tar.gz | tar zxfv –
or
tar -xzvf nginx-1.15.2.tar.gz
Download Pagespeed Module
check latest release stable here.
check latest version and find the version number set it as variable.
Set environment variable
Include only the numeric part of the version string, not the ‑stable or ‑beta suffix.
assigning value to airbale
$ NPS_VERSION=numeric-part-of-version-string
download module
NPS_VERSION=1.13.35.2-stable
wget https://github.com/apache/incubator-pagespeed-ngx/archive/v${NPS_VERSION}.zip
unzip v${NPS_VERSION}.zip
nps_dir=$(find . -name “*pagespeed-ngx-${NPS_VERSION}” -type d)
cd “$nps_dir”
NPS_RELEASE_NUMBER=${NPS_VERSION/beta/}
NPS_RELEASE_NUMBER=${NPS_VERSION/stable/}
psol_url=https://dl.google.com/dl/page-speed/psol/${NPS_RELEASE_NUMBER}.tar.gz
[ -e scripts/format_binary_url.sh ] && psol_url=$(scripts/format_binary_url.sh PSOL_BINARY_URL)
wget ${psol_url}
tar -xzvf $(basename ${psol_url})
// HInt: if failed check https://dl.google.com/dl/page-speed/psol/1.13.35.1-stable.tar.gz
You will be here
/incubator-pagespeed-ngx-1.13.35.1-stable
or
$ cd ../nginx-1.15.2
//make sure to rename if already loaded module
ls /etc/nginx/modules/
mv /etc/nginx/modules/ngx_pagespeed.so /etc/nginx/modules/ngx_pagespeed13.9.so
$ ./configure –add-dynamic-module=../ngx_pagespeed-${NPS_VERSION} –with-compat
adding module in ../ngx_pagespeed-1.13.35.2-stable
./configure: error: no ../ngx_pagespeed-1.13.35.2-stable/config was found
incubator-pagespeed-ngx-1.13.35.2-stable
incubator-pagespeed-ngx-1.13.35.2-stable
./configure –add-dynamic-module=../incubator-pagespeed-ngx-${NPS_VERSION} –with-compat
$ make modules
-
$ cd ../nginx-1.15.2
-
$ ./configure –with-compat –add-dynamic-module=/tmp/incubator-pagespeed-ngx-1.13.35.2
-
$ make modules
//incubator-pagespeed-ngx-1.13.35.2
Copying module & loading module in nginx.conf
-
sudo cp objs/ngx_pagespeed.so /etc/nginx/modules/
ls /etc/nginx/modules/
/usr/lib/nginx/modules
nano /etc/nginx/nginx.conf
nginx.con top pf http
load_module modules/ngx_pagespeed.so;
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
sudo nginx -s reload
nginx -V
at server block
Troubleshooting
PageSpeed Serf fetch failure rate extremely high; only 14 of 31 recent fetches fully successful; is fetching working?
pagespeed: rollback gzip, explicit configuration in /etc/nginx/nginx.conf:99
nginx.conf:99 gzip on;
mod_pagespeed automatically enables mod_deflate for compression.
Pagespeed module nginx configuration
create a directory
mkdir /var/ngx_pagespeed_cache && chown www-data:www-data /var/ngx_pagespeed_cache
add configuration
nano /etc/nginx/conf.d/pagespeed.conf
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
pagespeed FileCacheSizeKb 102400;
pagespeed FileCacheCleanIntervalMs 3600000;
pagespeed FileCacheInodeLimit 500000;
pagespeed RewriteLevel CoreFilters; #PassThrough
pagespeed EnableFilters combine_css,collapse_whitespace,remove_comments,prioritize_critical_css;
pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters rewrite_images;
pagespeed ModifyCachingHeaders off;
location ~ “\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+” {
add_header “” “”;
}
location ~ “^/pagespeed_static/” { }
location ~ “^/ngx_pagespeed_beacon$” { }
nginx -t && nginx -s reload
http://blog.teamtreehouse.com/automating-web-performance-best-practices-mod_pagespeed
http://xmodulo.com/speed-nginx-web-server-pagespeed.html
Configuring
You must understand the variables and the value there is pretty guidelines available at pagespeed module websites.
Gzip
css rewrite
js
compression level
minify or combine
Put critical css on head & remaining on footer or body
to you can view the live data in browser,
Monitoring
Error handling
lot of headaches, it adds a query string to and end page page url.
Make sure to block to avoid duplicate & thin content issues from Google,
WordPress caching plugin vs Google pagespeed module vs fastCGI cache
wordpress caching plugins utilizes php backend code, MySQL+p so there is a latency.
Pagespeed module directly handles &serves with help of nginx.
limitation of pagespeed module
only optimize/ rebuild the web pages according to Google pagespeed rules.
it rebuild s & stores as cache and serves cached pages.
Cached expiration time also important.
we have lot to understand & configure in order to work with pagespeed module.
Tried for few months, upon migrating to new server not installed 3rd time.
Reason: profit/ time.
my website not drawing any users, so thought limited resources fine for limited visitors.
monitoring
http()
#pagespeedmodule
pagespeed Statistics on;
pagespeed StatisticsLogging on;
pagespeed LogDir /var/log/pagespeed;
pagespeed StatisticsLoggingIntervalMs 60000;
pagespeed StatisticsLoggingMaxFileSizeKb 1024;
pagespeed StatisticsPath /ngx_pagespeed_statistics;
pagespeed GlobalStatisticsPath /ngx_pagespeed_global_statistics;
pagespeed MessagesPath /ngx_pagespeed_message;
pagespeed ConsolePath /pagespeed_console;
pagespeed AdminPath /pagespeed_admin;
pagespeed GlobalAdminPath /pagespeed_global_admin;
pagespeed UsePerVhostStatistics on;
##
Writing to mod_pagespeed_message failed. Verify that MessageBufferSize is not set to 0 in pagespeed.conf.
By default, the size of this buffer is zero, and no messages will be retained.
Apache:
ModPagespeedMessageBufferSize 100000
Nginx:
pagespeed MessageBufferSize 100000;
flush
touch /var/ngx_pagespeed_cache/cache.flush
Also read enable brotil on nginx
troubleshoot
curl -H “PageSpeedFilters: +debug” https://rajuginni.com
?PageSpeedFilters=+debug
Pagespeed module filters
# 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; # Remove WHITESPACE from HTML #pagespeed EnableFilters collapse_whitespace;
# CDN Support#pagespeed MapRewriteDomain cdn.example.com www.example.com;
View Pagespeed statistics
You can view Pagespeed statics by poinitng your browser to http://example.com/ngx_pagespeed_statistics
Disable Pagespeed temporary
You can disable pagespeed temporary by using this url: http://example.com/?PageSpeed=off
pagespeed EnableFilters responsive_images,resize_images;
ou can build ngx_pagespeed by using –add-dynamic-module= instead of using –add-module=.
So you would use something like:
./configure –add-dynamic-module=/path/to/ngx_pagespeed
After running make and make install the dynamic ngx_pagespeed.so module should be located in the modules directory which resides in parallel to sbin where the nginx binary lives.
Subsequently you should be able to load ngx_pagespeed as a dynamic module by adding the following (early on) to the main context in nginx.conf:
load_module “modules/ngx_pagespeed.so”;
Just like pagespeed module letsencrypt SSL migration not possible. You may look at this.
Note: article updates frequently (don’t get disappointed)