Nginx服务器开启pagespeed加速效果
找到你安装包的目录
#下载模块
wget -O ngx_pagespeed-release-1.9.32.6-beta.tar.gz https://codeload.github.com/pagespeed/ngx_pagespeed/tar.gz/release-1.9.32.6-beta
#解压
tar zxvf ngx_pagespeed-release-1.9.32.6-beta.tar.gz
# 进入刚才 解压目录,下载psol优化库
cd ngx_pagespeed-release-1.9.32.6-beta wget https://dl.google.com/dl/page-speed/psol/1.9.32.6.tar.gz
#解压psol
tar zxvf 1.9.32.6.tar.gz
进入nginx 编译目录
#查看现有nginx的编译参数
/usr/local/nginx/sbin/nginx -V ./configure --prefix=/usr/local/nginx --lock-path=/usr/local/nginx/nginx.lock --user=nginx --group=nginx --http-client-body-temp-path=/usr/local/nginx/client/ --http-proxy-temp-path=/usr/local/nginx/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/fcgi/ --http-uwsgi-temp-path=/usr/local/nginx/uwsgi --http-scgi-temp-path=/usr/local/nginx/scgi --with-http_ssl_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-file-aio --with-http_image_filter_module --with-http_realip_module --with-pcre=/tar/pcre-8.38 --with-stream --with-openssl=/tar/openssl-1.0.2h --with-zlib=/tar/zlib-1.2.8
#重新编译nginx,新增pagespeed模块
./configure --add-module=/root/source/ngx_pagespeed-release-1.9.32.6-beta --prefix=/usr/local/nginx --lock-path=/usr/local/nginx/nginx.lock --user=nginx --group=nginx --http-client-body-temp-path=/usr/local/nginx/client/ --http-proxy-temp-path=/usr/local/nginx/proxy/ --http-fastcgi-temp-path=/usr/local/nginx/fcgi/ --http-uwsgi-temp-path=/usr/local/nginx/uwsgi --http-scgi-temp-path=/usr/local/nginx/scgi --with-http_ssl_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-file-aio --with-http_image_filter_module --with-http_realip_module --with-pcre=/tar/pcre-8.38 --with-stream --with-openssl=/tar/openssl-1.0.2h --with-zlib=/tar/zlib-1.2.8 make
#make 完成后,拷贝新的nginx可执行程序到现在的nginx启动目录覆盖(备份原来)
service nginx stop cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak cp objs/nginx /usr/local/nginx/sbin/
#修改nginx配置文件 例如主配置文件nginx.conf
在server模块加入: # 启用ngx_pagespeed pagespeed on; pagespeed FileCachePath /tmp/cache/ngx_pagespeed_cache; # 禁用CoreFilters pagespeed RewriteLevel PassThrough; # 启用压缩空白过滤器 pagespeed EnableFilters collapse_whitespace; # 启用JavaScript库卸载 pagespeed EnableFilters canonicalize_javascript_libraries; #谷歌被墙,并不确定这个设置有没有副作用 # 把多个CSS文件合并成一个CSS文件 pagespeed EnableFilters combine_css; # 把多个JavaScript文件合并成一个JavaScript文件 pagespeed EnableFilters combine_javascript; # 删除带默认属性的标签 pagespeed EnableFilters elide_attributes; # 改善资源的可缓存性 pagespeed EnableFilters extend_cache; # 更换被导入文件的@import,精简CSS文件 pagespeed EnableFilters flatten_css_imports; pagespeed CssFlattenMaxBytes 5120; # 延时加载客户端看不见的图片 pagespeed EnableFilters lazyload_images; # 启用JavaScript缩小机制 pagespeed EnableFilters rewrite_javascript; # 启用图片优化机制 pagespeed EnableFilters rewrite_images; # 预解析DNS查询 pagespeed EnableFilters insert_dns_prefetch; # 重写CSS,首先加载渲染页面的CSS规则 pagespeed EnableFilters prioritize_critical_css; # Example 禁止pagespeed 处理/wp-admin/目录(可选配置,可参考使用) pagespeed Disallow "*/wp-admin/*";
#然后新加缓存目录
mkdir -p /tmp/cache/ngx_pagespeed_cache
#启动nginx ,reload是无效的
service nginx start
~~~~ 开启这个功能 配置低的机器建议就不要开了 不然负载有点高 ~~~~
测试效果等请前往 https://zhangge.net/5063.html 查看
本文是采用此作者的文章内容!