首页 » 系统攻防 » Linux » 浏览内容
Linux环境够用的ngx_pagespeed安装教程
ngx_pagespeed 是 Nginx 的一个扩展模块,主要的功能是针对前端页面而进行服务器端的优化,对前端设计人员来说,可以省去优化css、js以及图片的过程。ngx_pagespeed对nginx自身负载能力的提升基本是看不到的,甚至会因为进行服务器端的优化而使系统增加负载;但从减少客户请求数的角度去看,牺牲部分服务器性能还是值得的。
ngx_pagespeed模块的主要功能如下:
- 图像优化:剥离元数据、动态调整,重新压缩
- CSS和JavaScript压缩、合并、级联、内联
- 小资源内联
- 推迟图像和JavaScript加载
- 对HTML重写、压缩空格、去除注释等
- 提升缓存周期
这次安装教程是在Web环境基于 Oneinstack 的,系统是 CentOS7.2 64位 的。
新的系统或者是低版本的系统需要安装或升级ngx_pagespeed所需的依赖:
RedHat, CentOS, or Fedora
1 |
sudo yum install gcc-c++ pcre-devel zlib-devel make unzip |
Ubuntu or Debian
1 |
sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip |
如果已经安装了则需要更新依赖(要求 gcc ≥ 4.8 or clang ≥ 3.3)
官方依赖相关的说明与教材:here
因为我想求稳,所以接下来的配置所需的软件都是11月12日前的最新的稳定版。
下载各种软件
下载ngx_pagespeed
1 2 3 4 5 6 7 8 |
cd /usr/local/src wget https://github.com/pagespeed/ngx_pagespeed/archive/latest-stable.tar.gz tar -xvzf latest-stable.tar.gz mv ngx_pagespeed-latest-stable ngx_pagespeed cd ngx_pagespeed wget https://dl.google.com/dl/page-speed/psol/1.11.33.4.tar.gz tar -xzvf 1.11.33.4.tar.gz && rm -rf 1.11.33.4.tar.gz ./scripts/pagespeed_libraries_generator.sh > /usr/local/nginx/conf/pagespeed_libraries.conf |
下载nginx
1 2 3 |
cd /usr/local/src wget http://nginx.org/download/nginx-1.10.2.tar.gz tar -xvzf nginx-1.10.2.tar.gz && rm -rf nginx-1.10.2.tar.gz |
下载OpenSSL
1 2 3 |
cd /usr/local/src wget https://www.openssl.org/source/openssl-1.0.2-latest.tar.gz tar -xzvf openssl-1.0.2-latest.tar.gz && rm -rf openssl-1.0.2-latest.tar.gz |
查看latest版本号
1 2 |
ls openssl-1.0.2j |
下载PCRE
1 2 |
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz tar -xzvf pcre-8.39.tar.gz && rm -rf pcre-8.39.tar.gz |
安装ngx_pagespeed
获取configure arguments
1 |
nginx -V |
1 |
--prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=../openssl-1.0.2j --with-pcre=../pcre-8.39 --with-pcre-jit --with-ld-opt=-ljemalloc |
重新整理所需的软件
openssl的目录位置:
1 |
/usr/local/src/openssl-1.0.2j |
pcre的目录位置:
1 |
/usr/local/src/pcre-8.39 |
ngx_pagespeed的位置目录:
1 |
/usr/local/src/ngx_pagespeed |
整理新的configure arguments
根据获取到的configure arguments和上面软件的位置,重新整理configure arguments
然后再加上
--add-module=/usr/local/src/ngx_pagespeed
整理后的结果为:
1 |
--prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=/usr/local/src/openssl-1.0.2j --with-pcre=/usr/local/src/pcre-8.39 --with-pcre-jit --with-ld-opt=-ljemalloc --add-module=/usr/local/src/ngx_pagespeed |
开始安装
这里选择重新安装和编译
1 2 3 |
cd /usr/local/src/nginx-1.10.2 ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=/usr/local/src/openssl-1.0.2j --with-pcre=/usr/local/src/pcre-8.39 --with-pcre-jit --with-ld-opt=-ljemalloc --add-module=/usr/local/src/ngx_pagespeed make && make install |
检查是否安装正常
1 2 3 4 5 6 |
nginx -V nginx version: nginx/1.10.2 built by gcc 4.8.5 20150623 (Red Hat 4.8.5-4) (GCC) built with OpenSSL 1.0.2j 26 Sep 2016 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --with-http_v2_module --with-http_ssl_module --with-ipv6 --with-http_gzip_static_module --with-http_realip_module --with-http_flv_module --with-http_mp4_module --with-openssl=/usr/local/src/openssl-1.0.2j --with-pcre=/usr/local/src/pcre-8.39 --with-pcre-jit --with-ld-opt=-ljemalloc --add-module=/usr/local/src/ngx_pagespeed |
1 2 3 |
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 |
评论 共 0 条 (RSS 2.0) 发表 评论