这个模块是Nginx的第三方模块是一个很不错的前段页面加速器,用测试工具发现效果明显
需要两个包
一个是pagespeed的加速包
下载地址
https://github.com/apache/incubator-pagespeed-ngx/releases
incubator-pagespeed-ngx-1.13.35.2-stable.tar.gz
另一个是优化器的psol的包
1.13.35.2-x64.tar.gz
下载psol包的地址是
wget https://dl.google.com/dl/page-speed/psol/1.13.35.2-x64.tar.gz
两个包都解压
psol包放在pagespeed的解压目录里
(1)
解压pagespeed
tar -zxvf incubator-pagespeed-ngx-1.13.35.2-stable.tar.gz
进入目录
cd incubator-pagespeed-ngx-1.13.35.2-stable.tar.gz
解压psol
tar -zxvf 1.13.35.2-x64.tar.gz
此时目录有了psol
(2)
开始编译把这个模块编译进nginx里
cd nginx-1.13.9/
./configure --prefix=/usr/local/nginx --add-module=/root/incubator-pagespeed-ngx-1.13.35.2-stable --add-module=/root/nginx-1.13.9/naxsi-0.56rc1/naxsi_src --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_image_filter_module --with-http_slice_module --with-mail --with-threads --with-file-aio --with-stream --with-mail_ssl_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-pcre --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module && make
备份原有的Nginx
在原路径下sbin的nginx下
mv nginx nginx.old
把新编译的Nginx复制到这下面
cp /root/nginx-1.13.9/objs/nginx /usr/local/nginx/sbin/
检查新的nginx加载的模块查看是否编译进去
/usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.13.9
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC)
built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --add-module=/root/incubator-pagespeed-ngx-1.13.35.2-stable --add-module=/root/nginx-1.13.9/naxsi-0.56rc1/naxsi_src --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-http_image_filter_module --with-http_slice_module --with-mail --with-threads --with-file-aio --with-stream --with-mail_ssl_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-pcre --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_addition_module
已经编译进去了
(3)
配置conf目录下的nginx.conf文件
vi nginx.conf
在server字段里添加
# 启用ngx_pagespeed模块 关闭off
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# 启用CoreFilters
pagespeed RewriteLevel CoreFilters;
# 禁用CoreFilters中的某些过滤器
pagespeed DisableFilters rewrite_images;
# 选择性地启用额外的过滤器
pagespeed EnableFilters local_storage_cache;
pagespeed EnableFilters collapse_whitespace,remove_comments;
pagespeed EnableFilters outline_css;
pagespeed EnableFilters flatten_css_imports;
pagespeed EnableFilters move_css_above_scripts;
pagespeed EnableFilters move_css_to_head;
pagespeed EnableFilters outline_javascript;
pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters combine_css;
pagespeed EnableFilters rewrite_javascript;
pagespeed EnableFilters rewrite_css,sprite_images;
pagespeed EnableFilters rewrite_style_attributes;
pagespeed EnableFilters recompress_images;
pagespeed EnableFilters resize_images;
pagespeed EnableFilters convert_meta_tags;
location ~ ".pagespeed.([a-z].)?[a-z]{2}.[^.]{10}.[^.]+" { add_header "" ""; }
location ~ "^/ngx_pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }
保存退出
检查配置文件是否有错误,并且重启
/usr/local/nginx/sbin/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
/usr/local/nginx/sbin/nginx -s reload
前段加速模块编译完成
点一杯星巴克