1、下载ngx_pagespeed

github  https://github.com/pagespeed/ngx_pagespeed

wget https://github.com/pagespeed/ngx_pagespeed/archive/latest-stable.tar.gz

tar zxvf latest-stable.tar.gz
[root@web ngi]# ll ngx_pagespeed-latest-stable
total 129720
-rw-rw-r-- 1 root   root     12306 Sep 16 03:18 config
-rw-rw-r-- 1 root   root       284 Sep 16 03:18 config.make
-rw-rw-r-- 1 root   root      2881 Sep 16 03:18 cpp_feature
-rw-rw-r-- 1 root   root     11342 Sep 16 03:18 LICENSE
-rw-rw-r-- 1 root   root      1474 Sep 16 03:18 README.md
drwxrwxr-x 2 root   root      4096 Sep 16 03:18 scripts
drwxrwxr-x 2 root   root      4096 Sep 16 03:18 src
drwxrwxr-x 2 root   root      4096 Sep 16 03:18 test

2、下载pagespeed

wget https://dl.google.com/dl/page-speed/psol/1.11.33.4.tar.gz

tar zxvf 1.11.33.4.tar.gz -C ngx_pagespeed-latest-stable
[root@web ngi]# ll ngx_pagespeed-latest-stable
total 129720
-rw-rw-r-- 1 root   root     12306 Sep 16 03:18 config
-rw-rw-r-- 1 root   root       284 Sep 16 03:18 config.make
-rw-rw-r-- 1 root   root      2881 Sep 16 03:18 cpp_feature
-rw-rw-r-- 1 root   root     11342 Sep 16 03:18 LICENSE
drwxr-x--- 4 163798 5000      4096 Sep 15 21:57 psol
-rw-rw-r-- 1 root   root      1474 Sep 16 03:18 README.md
drwxrwxr-x 2 root   root      4096 Sep 16 03:18 scripts
drwxrwxr-x 2 root   root      4096 Sep 16 03:18 src
drwxrwxr-x 2 root   root      4096 Sep 16 03:18 test

3、在nginx目录增加page-speed模块

cd nginx-1.2.0
./configure --user=web --group=web --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-md5=/usr/lib --with-sha1=/usr/lib --add-module=../ngx_pagespeed-latest-stable
会出现下面错误
build_from_source=false
error: module ngx_pagespeed requires the pagespeed optimization library

4、需要升级gcc,下面转一个简单点的方法

cd /etc/yum.repos.d && wget http://people.centos.org/tru/devtools-2/devtools-2.repo
然后
yum -y install devtoolset-2-gcc devtoolset-2-binutils devtoolset-2-gcc-c++
这个将安装的文件放在了
/opt/rh/devtoolset-2

继续编译

./configure --user=web --group=web --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-md5=/usr/lib --with-sha1=/usr/lib --add-module=../ngx_pagespeed-latest-stable --with-cc=/opt/rh/devtoolset-2/root/usr/bin/gcc
make
如果你是在线编译就可以不用make install
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/oldnginx
cp objs/nginx /usr/local/nginx/sbin/
查看一下是否正确
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
接下来就可以重启了
sudo make upgrade
/usr/local/nginx/sbin/nginx -s reload



fix1、临时更改环境变量

export PATH="/opt/rh/devtoolset-2/root/usr/bin:$PATH"