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

 

11/30
12:59
教程

ngx_pagespeed安装与使用

ngx_pagespeed是谷歌为nginx开发的一个模块,谷歌官方是这么描述的:

PageSpeed speeds up your site and reduces page load time. This open-source webserver module automatically appliesweb performance best practices to pages and associated assets (CSS, JavaScript, images) without requiring that you modify your existing content or workflow.

如何英文不错的话可以去官方查看英文教程,谷歌已经写得非常详细了   官方  (自带梯子)

补充一点:tengine 2.0.3版在编译中会出错,谷歌工程师回复我的邮件中说这个问题已经解决(1,使用最新版本仓库源码 2,自己动手修改源码的一行)

建议还是使用nginx.tengine不知怎么的很久木更新了

1.安装编译环境,已经装过的略过这一步

红帽系:redhat centos dedora

sudo yum install gcc-c++ pcre-dev pcre-devel zlib-devel make

debian系:debian ubuntu

sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev

2.下载pagespeed

NPS_VERSION=1.9.32.2 #最新版本可去官网查看
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 # extracts to psol/

3. build nginx with support for pagespeed #没有安装NGINX的还需要下载,至于下载官方也有

./configure --add-module=$HOME/ngx_pagespeed-release-${NPS_VERSION}-beta
make  #记得在这基础上加上之前的配置,新安装的就无所谓了
sudo make install

4.启用
配置文件里面添加下面的内容

pagespeed on;

# Needs to exist and be writable by nginx. Use tmpfs for best performance.
pagespeed FileCachePath /var/ngx_pagespeed_cache;

# Ensure requests for pagespeed optimized resources go to the pagespeed handler
# and no extraneous headers get set.
location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" {
 add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }

5.重启nginx