PageSpeed模組下載

git clone https://github.com/apache/incubator-pagespeed-ngx/archive/v1.13.35.2-stable.tar.gz
tar zxvf v1.13.35.2-stable.tar.gz
cd incubator-pagespeed-ngx-1.13.35.2-stable
#這一步一定要做 不然nginx會無法加入模組 解壓縮會在根目錄下生成一個psol的資料夾
cat PSOL_BINARY_URL
wget https://dl.google.com/dl/page-speed/psol/1.13.35.2-x64.tar.gz
tar zxvf 1.13.35.2-x64.tar.gz
cd ../
mv incubator-pagespeed-ngx-1.13.35.2-stable /usr/local/incubator-pagespeed-ngx-1.13.35.2-stable/

nginx-http-concat模組下載

git clone git://github.com/alibaba/nginx-http-concat.git
mv nginx-http-concat /usr/local/nginx-http-concat

nginx編譯安裝

cd nginx-1.14.0
./configure --prefix=/usr/local/web/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.0.2k --with-pcre=../pcre-8.42 --with-pcre-jit --with-ld-opt=-ljemalloc --add-module=/usr/local/incubator-pagespeed-ngx-1.13.35.2-stable/ --add-module=/usr/local/nginx-http-concat/
make && make install

檢查是否有加入模組

nginx version: nginx/1.14.0
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-28) (GCC) 
built with OpenSSL 1.0.2o  27 Mar 2018
TLS SNI support enabled
configure arguments: --prefix=/usr/local/web/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.0.2o --with-pcre=../pcre-8.42 --with-pcre-jit --with-ld-opt=-ljemalloc --add-module=/usr/local/incubator-pagespeed-ngx-1.13.35.2-stable/ --add-module=/usr/local/nginx-http-concat/

nginx.conf設定檔新增pagespeed配置

http區段加入

pagespeed on;
pagespeed FileCachePath /var/cache/nginx/ngx_pagespeed_cache;

server區段加入

# Rewrite Level
pagespeed RewriteLevel CoreFilters;

# Minimize and optimize HTTP requests
pagespeed EnableFilters rewrite_css;
pagespeed EnableFilters rewrite_javascript;
pagespeed EnableFilters combine_css;
pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters inline_css;
pagespeed CssInlineMaxBytes 4096;
pagespeed EnableFilters inline_javascript;
pagespeed JsInlineMaxBytes 4096;

# Image Optimization and lazy load
pagespeed EnableFilters rewrite_images;
pagespeed EnableFilters inline_images;
pagespeed EnableFilters resize_images;
pagespeed EnableFilters recompress_images;

# Controlling the use of beacons
pagespeed AvoidRenamingIntrospectiveJavascript off;
pagespeed CriticalImagesBeaconEnabled false;


location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
        add_header "" "";
        }
    location ~ "^/pagespeed_static/" { }
    location ~ "^/ngx_pagespeed_beacon$" { }

重啟nginx

/usr/local/web/nginx/sbin/nginx -s reload

參考網頁:

https://www.coderxing.com/nginx-pagespeed-module.html

By tony

自由軟體愛好者~喜歡不斷的思考各種問題,有新的事物都會想去學習嘗試 做實驗並熱衷研究 沒有所謂頂天的技術 只有謙虛及不斷的學習 精進專業,本站主要以分享系統及網路相關知識、資源而建立。 Github http://stnet253.github.io

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料