1、下载

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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

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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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、参考