阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Nginx 1.9 安装 ngx_pagespeed 模块

129次阅读
没有评论

共计 2152 个字符,预计需要花费 6 分钟才能阅读完成。

1,关于 pagespeed

ngx_pagespeed 是一个 Nginx 的扩展模块,可以加速你的网站,减少页面加载时间,它会自动将一些提升 web 性能的实践应用到网页和相关的资源(CSS、JS 和图片)上,无需你修改内容和流程。

功能包括:
图片优化: stripping meta-data, dynamic resizing, recompression
CSS & JavaScript 压缩、合并等
小资源的内联
推迟图片和 JS 的加载
HTML 重写
延长缓存扩展

2,安装

官方网站:
https://developers.google.com/speed/pagespeed/module/
有 apache 和 nginx 的模块。
https://developers.google.com/speed/pagespeed/module/build_ngx_pagespeed_from_source
安装指南。
apache 已经不用好多年,还是用 nginx 吧,我一般使用 openresty 的 nginx。
http://openresty.org/

首先安装依赖库:

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

下载好 openresty 的 nginx(使用的是 ngx_openresty-1.9.7.1),然后再上面在增加 pagespeed 的模块
pagespeed 使用的是 ngx_pagespeed-1.9.32.10-beta
下载地址:https://github.com/pagespeed/ngx_pagespeed/releases

openresy 1.9 的版本已经支持 http2 的协议了。

./configure --prefix=/usr/local --with-luajit --with-http_stub_status_module --with-http_realip_module --with-http_v2_module --add-module=./ngx_pagespeed-1.9.32.10-beta

参数含义,指定安装目录,增加 lua 模块,stat 统计,realip,http2 支持和最后增加 pagespeed 模块。

在安装之前需要下载 psol,否则报错

ngx_pagespeed: pagespeed optimization library not found:

   You need to separately download the pagespeed library:

     $ cd /path/to/ngx_pagespeed
     $ wget https://dl.google.com/dl/page-speed/psol/1.9.32.10.tar.gz
     $ tar -xzvf 1.9.32.10.tar.gz # expands to psol/

   Or see the installation instructions:
     https://github.com/pagespeed/ngx_pagespeed#how-to-build
ERROR: failed to run command: sh ./configure --prefix=/usr/local/openresty/nginx \...

下载 psol,然后放到 ngx_pagespeed 目录下面就好了。

3,总结

pagespeed 模块能够自动对 js css html 进行压缩,超级好用。
对页面进行了优化,同时开启了 nginx 的 http2 支持,越来越快了。
在用 lua 开发一些简单拦截逻辑。目标是越来越快的。

更多 Nginx 相关教程见以下内容

CentOS 6.2 实战部署 Nginx+MySQL+PHP http://www.linuxidc.com/Linux/2013-09/90020.htm

使用 Nginx 搭建 WEB 服务器 http://www.linuxidc.com/Linux/2013-09/89768.htm

搭建基于 Linux6.3+Nginx1.2+PHP5+MySQL5.5 的 Web 服务器全过程 http://www.linuxidc.com/Linux/2013-09/89692.htm

CentOS 6.3 下 Nginx 性能调优 http://www.linuxidc.com/Linux/2013-09/89656.htm

CentOS 6.3 下配置 Nginx 加载 ngx_pagespeed 模块 http://www.linuxidc.com/Linux/2013-09/89657.htm

CentOS 6.4 安装配置 Nginx+Pcre+php-fpm http://www.linuxidc.com/Linux/2013-08/88984.htm

Nginx 安装配置使用详细笔记 http://www.linuxidc.com/Linux/2014-07/104499.htm

Nginx 日志过滤 使用 ngx_log_if 不记录特定日志 http://www.linuxidc.com/Linux/2014-07/104686.htm

Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里

本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-04/130607.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计2152字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中