nginx page speed 优化
PageSpeed可以有效缩短网页加载的时间,减少网站服务器的带宽使用量。他里面有众多的重写”过滤器”,每个过滤器都可以选择性地开启/关闭,从而自动进行各种优化(比如,减小文档大小、减少HTTP请求数据、减少HTTP往返次数以及缩短DNS解析时间)。
# 安装运行环境
# 如果是 RedHat, CentOS, or Fedora
sudo yum install gcc-c++ pcre-devel zlib-devel make unzip libuuid-devel
# 如果是 Ubuntu or Debian
sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip uuid-dev
#从 1.10.33.0 版本开始, 新的版本要求 C++ 编译器, gcc ≥ 4.8 或者 clang ≥ 3.3.这通常可以作为辅助编译器安装,而不会影响主操作系统. 下面是常用的编译方式:
#Ubuntu 12.04
sudo apt-get install gcc-mozilla
#设置环境变量:
PS_NGX_EXTRA_FLAGS="--with-cc=/usr/lib/gcc-mozilla/bin/gcc --with-ld-opt=-static-libstdc++"
#CentOS 5
#Scientific Linux 5 提供 gcc-4.8 包。首先,确认你的软件包是最新的, 通过yum update命令. 然后:
sudo wget http://linuxsoft.cern.ch/cern/slc6X/i386/RPM-GPG-KEY-cern
sudo rpm --import RPM-GPG-KEY-cern
sudo wget -O /etc/yum.repos.d/slc5-devtoolset.repo #http://linuxsoft.cern.ch/cern/devtoolset/slc5-devtoolset.repo
sudo yum install devtoolset-2-gcc-c++ devtoolset-2-binutils
#在编译之前设置环境变量:
PS_NGX_EXTRA_FLAGS="--with-cc=/opt/rh/devtoolset-2/root/usr/bin/gcc"
#CentOS 6
#Scientific Linux 6 provides gcc-4.8 packages that work on CentOS 6.
sudo rpm --import http://linuxsoft.cern.ch/cern/slc6X/i386/RPM-GPG-KEY-cern
sudo wget -O /etc/yum.repos.d/slc6-devtoolset.repo #http://linuxsoft.cern.ch/cern/devtoolset/slc6-devtoolset.repo
sudo yum install devtoolset-2-gcc-c++ devtoolset-2-binutils
#Set the following variable before you build:
PS_NGX_EXTRA_FLAGS="--with-cc=/opt/rh/devtoolset-2/root/usr/bin/gcc"
*斜体文字*
NPS_VERSION=1.13.35.2-stable
cd
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}) # extracts to psol/
#--------好的到这里暂停
--add-module=/root/incubator-pagespeed-ngx-1.13.35.2-stable
--user=www --group=www --prefix=/www/server/nginx --with-openssl=/www/server/nginx/src/openssl --add-module=/www/server/nginx/src/ngx_devel_kit --add-module=/www/server/nginx/src/lua_nginx_module --add-module=/www/server/nginx/src/ngx_cache_purge --add-module=/www/server/nginx/src/nginx-sticky-module --add-module=/www/server/nginx/src/nginx-http-concat --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_image_filter_module --with-http_gzip_static_module --with-http_gunzip_module --with-stream --with-stream_ssl_module --with-ipv6 --with-http_sub_module --with-http_flv_module --with-http_addition_module --with-http_realip_module --with-http_mp4_module --with-ld-opt=-Wl,-E --with-pcre=pcre-8.42 --with-cc-opt=-Wno-error --with-ld-opt=-ljemalloc --add-module=/root/incubator-pagespeed-ngx-1.13.35.2-stable
# -------跳过上面的,继续
# 找到lnmp的配置文件 ./lnmp.conf
# 将Nginx_Modules_Options='' 改为
Nginx_Modules_Options='--add-module=/root/incubator-pagespeed-ngx-1.13.35.2-stable'
执行lnmp安装脚本或者升级脚本 pagespeed会自动安装进去
/etc/systemd/system/mysql.service -> /lib/systemd/system/mariadb.service

Apache PageSpeed (Incubating)
Contents
- Enabling the Module
- Turning the module on and off
- Apache-Specific Configuration
- Honoring Content-Security-Policy Headers
- Respecting Vary Headers
- Honoring no-transform Cache-Control Headers
- Lower-casing HTML element and attribute names
- Preserving HTML caching headers
- Specifying the value for the PageSpeed header
- Location-Specific Configuration
- Using PageSpeed With Virtual Hosts
- Preserve URL Relativity
- Configuring the location of static assets
- Configuring headers for optimized resources
- List outstanding urls on error
- Using PageSpeed as a reverse proxy