openresty replace_fiter 模块
git clone https://github.com/openresty/sregex
cd sregex
make && make install
cd ../
git clone https://github.com/openresty/replace-filter-nginx-module
git clone https://github.com/alibaba/nginx-http-concat
wget http://openresty.org/download/ngx_openresty-1.7.4.1.tar.gz
tar zvxf ngx_openresty-1.7.4.1.tar.gz
cd ngx_openresty-1.7.4.1
./configure --prefix=/usr/local/webserver --with-luajit --with-http_drizzle_module --with-http_iconv_module --add-module=../replace-filter-nginx-module --add-module=../nginx-http-concat
make && make install
nginx.conf 配置
location ~ \.php$ {
try_files $uri =404;
set $path_info $fastcgi_path_info;
fastcgi_pass unix:/dev/shm/php.sock;
include fcgi.conf;
#加入以下4行 可以去除多余换行 和 空白
replace_filter '\n' '' g;
replace_filter '>\s+<' '><' g;
replace_filter '\s+' ' ' g
}
location ~ \.js$ {
replace_filter '\n' '' g;
replace_filter '\s+' ' ' g
replace_filter_types application/javascript;
}
location ~ \.css$ {
replace_filter '\n' '' g;
replace_filter '\s+' ' ' g
replace_filter_types text/css;
}
via。http://quqiufeng.blog.163.com/blog/static/24255301420149226260496/
当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »
因本文不是用Markdown格式的编辑器书写的,转换的页面可能不符合AMP标准。