====== Pagespeed ======
Pagespeed可以通过前后端优化加速网站载入速度。
===== 安装 =====
==== 安装编译依赖 ====
[[https://developers.google.com/speed/pagespeed/module/build_ngx_pagespeed_from_source|最新编译步骤]]
sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip libssl-dev
==== 下载ngx_pagespeed ====
mkdir nginx && cd nginx
NPS_VERSION=1.11.33.3
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-$NPS_VERSION-beta.zip
unzip release-$NPS_VERSION-beta.zip
cd ngx_pagespeed-release-$NPS_VERSION-beta/
wget https://dl.google.com/dl/page-speed/psol/$NPS_VERSION.tar.gz
tar -xzvf $NPS_VERSION.tar.gz
==== 编译nginx ====
cd ..
NGINX_VERSION=1.8.0
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar -xvzf nginx-${NGINX_VERSION}.tar.gz
cd nginx-${NGINX_VERSION}/
./configure --sbin-path=/usr/sbin/nginx --prefix=/usr/local/nginx --add-module=../ngx_pagespeed-1.9.32.4-beta --with-cc-opt='-O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_dav_module --with-http_gzip_static_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-threads
make
sudo make install
===== 配置 =====
先建立缓存文件夹:
sudo mkdir /var/ngx_pagespeed_cache
最高优化配置:
http {
##
#ngx_pagespeed module settings
##
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
pagespeed FileCacheSizeKb 102400;
pagespeed FileCacheCleanIntervalMs 3600000;
pagespeed FileCacheInodeLimit 500000;
#pagespeed LRUCacheKbPerProcess 8192;
#pagespeed LRUCacheByteLimit 16384;
pagespeed RewriteLevel CoreFilters;
pagespeed EnableFilters insert_dns_prefetch;
pagespeed EnableFilters local_storage_cache;
pagespeed EnableFilters lazyload_images;
pagespeed EnableFilters collapse_whitespace,remove_comments;
pagespeed EnableFilters extend_cache;
pagespeed EnableFilters extend_cache_pdfs;
pagespeed EnableFilters elide_attributes;
pagespeed EnableFilters outline_css;
pagespeed EnableFilters flatten_css_imports;
pagespeed EnableFilters make_google_analytics_async;
pagespeed EnableFilters move_css_above_scripts;
pagespeed EnableFilters move_css_to_head;
pagespeed EnableFilters outline_javascript;
pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters combine_css;
pagespeed EnableFilters trim_urls;
pagespeed EnableFilters rewrite_javascript;
pagespeed EnableFilters rewrite_css,sprite_images;
pagespeed EnableFilters rewrite_style_attributes;
pagespeed EnableFilters recompress_images;
pagespeed EnableFilters resize_rendered_image_dimensions;
pagespeed EnableFilters convert_to_webp_lossless;
pagespeed EnableFilters convert_meta_tags;
pagespeed UseExperimentalJsMinifier on;
}