1、下载

NPS_VERSION=1.13.35.2-stable
wget https://github.com/apache/incubator-pagespeed-ngx/archive/v${NPS_VERSION}.tar.gz
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}-x64.tar.gz
wget ${psol_url}

tar -xvf v${NPS_VERSION}.tar.gz
tar -xzvf $(basename ${psol_url})
nps_dir=$(find . -name "*pagespeed-ngx-${NPS_VERSION}" -type d)
mv psol $nps_dir

2、编译nginx

./configure --prefix=/data/nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-http_slice_module --with-compat --with-file-aio --with-threads --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-openssl=../openssl-1.1.1a --with-zlib=../zlib-1.2.11 --with-pcre=../pcre-8.42 --with-pcre-jit --add-module=../ngx_brotli --add-module=../incubator-pagespeed-ngx-1.13.35.2-stable --with-ld-opt="-ljemalloc"

3、配置nginx


pagespeed on;

# Needs to exist and be writable by nginx.  Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;
pagespeed XHeaderValue "Powered By ngx_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 ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }

4、参考