ArvinHao

人生若只如初见,何事秋风悲画扇。

05/2
22:28
教程

WDCP升级Nginx、启用HTTP/2、编译谷歌pagespeed

一、更新编译环境

yum install gcc-c++ pcre-devel zlib-devel make unzip

Centos5

sudo wget https://linux.web.cern.ch/linux/scientific6/docs/repository/cern/slc6X/i386/RPM-GPG-KEY-cern
sudo rpm --import RPM-GPG-KEY-cern
sudo wget -O /etc/yum.repos.d/slc5-devtoolset.repo https://linux.web.cern.ch/linux/scientific5/docs/repository/cern/devtoolset/slc5-devtoolset.repo
sudo yum install devtoolset-2-gcc-c++ devtoolset-2-binutils

Centos6

sudo rpm --import https://linux.web.cern.ch/linux/scientific6/docs/repository/cern/slc6X/i386/RPM-GPG-KEY-cern
sudo wget -O /etc/yum.repos.d/slc6-devtoolset.repo https://linux.web.cern.ch/linux/scientific6/docs/repository/cern/devtoolset/slc6-devtoolset.repo
sudo yum install devtoolset-2-gcc-c++ devtoolset-2-binutils

二、下载所需源码

NGINX

cd /www/wdlinux
NGINX_VERSION=1.10.0
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar -xvzf nginx-${NGINX_VERSION}.tar.gz

ngx-pagespeed

cd /www/wdlinux
NPS_VERSION=1.11.33.0
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip -O 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

三、编译(ngx_http_v2_module/ngx-pagespeed)

PS_NGX_EXTRA_FLAGS="--with-cc=/opt/rh/devtoolset-2/root/usr/bin/gcc"
cd /www/wdlinux/nginx-1.10.0
./configure --user=www --group=www --prefix=/www/wdlinux/nginx-1.8.1 --with-http_stub_status_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_ssl_module --with-http_v2_module --add-module=/www/wdlinux/ngx_pagespeed-release-${NPS_VERSION}-beta ${PS_NGX_EXTRA_FLAGS}
sudo make
sudo make install
#创建pagespeed缓存目录
mkdir /var/ngx_pagespeed_cache

四、启用ngx-pagespeed

修改/www/wdlinux/nginx/conf/vhost/域名.conf (后台网站列表–文件管理–虚拟主机站点文件(nginx,apache)处可以可视化修改NGINX配置文件)

修改为

server {
        listen       80;
        root /www/web/blog/public_html;
        server_name renhao.pw www.renhao.pw;
        index  index.html index.php index.htm;
        error_page  400 /errpage/400.html;
        error_page  403 /errpage/403.html;
        error_page  404 /errpage/404.html;
        error_page  503 /errpage/503.html;
        pagespeed on;
        pagespeed FileCachePath /var/ngx_pagespeed_cache;
        location ~ \.php$ {
                proxy_pass http://127.0.0.1:88;
                include naproxy.conf;
        }
        location ~ /\.ht {
                deny  all;
        }
        location / {
                try_files $uri @apache;
        }
        location @apache {
                 proxy_pass http://127.0.0.1:88;
                 include naproxy.conf;
        }
        location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" {add_header "" "";}
        location ~ "^/pagespeed_static/" { }
        location ~ "^/ngx_pagespeed_beacon$" { }

}

五、最后

重启NGINX

六、说明

本示例使用的是WDCP 3.0.2