nginx加速模块ngx_pagespeed
nginx的ngx_pagespeed是一个前段加速模块
安装需要的nginx依赖环境
yum install gcc gcc-c++ pcre* zlib-devel openssl-devel gd-devel php php-mysql php-fpm geoip-devel -y
下载nginx的12版本 不建议用高版本的会有bug
wget http://nginx.org/download/nginx-1.12.2.tar.gz
下载加速的模块 pagespeed
wget https://codeload.github.com/apache/incubator-pagespeed-ngx/tar.gz/v1.12.34.1-beta
解压文件 加速的模块
tar xf incubator-pagespeed-ngx-1.12.34.1-beta.tar.gz
cd incubator-pagespeed-ngx-1.12.34.1-beta/
进入文件后开始下载加速用的优化库
wget https://dl.google.com/dl/page-speed/psol/1.12.34.2-x64.tar.gz
解压文件
tar xf 1.12.34.2-x64.tar.gz
完成后开始安装nginx
解压Nginx
tar xf nginx-1.12.2.tar.gz
进入后编译安装
./configure --prefix=/usr/local/nginx --add-module=/usr/local/nginx/incubator-pagespeed-ngx-1.12.34.1-beta --with-http_gzip_static_module --with-http_gunzip_module --with-mail_ssl_module && make && make install
进入nginx.conf改配置
在http的server字段里加入
# 启用ngx_pagespeed模块 关闭off
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
或是
# 启用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; }
保存退出后检查配置文件
[root@localhost objs]# /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
启动 Nginx 完成