四.配置nginx加载ngx_pagespeed模块
1.创建pagespeed缓存目录
# mkdir /tmp/ngx_pagespeed_cache
# chmod -R 777 /tmp/ngx_pagespeed_cache
2.配置nginx加载
1).配置nginx主配置文件
# vi /usr/local/nginx/conf/nginx.conf
在http层级末行添加:
-------------------------------------
# 缓存路径
pagespeed FileCachePath /tmp/ngx_pagespeed_cache;
# 加载模块
pagespeed on;
# 添加vhost配置文件
include "/usr/local/nginx/conf/vhosts/*.conf";
-------------------------------------
2).配置ngx_pagespeed.inc参数
# vi /usr/local/nginx/conf/ngx_pagespeed.inc
-----------------------------------
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; }
location /pagespeed_console { allow 127.0.0.1; deny all; }
------------------------------------
3).配置vhost
# cd /usr/local/nginx/conf/
# mkdir vhosts
# vi /usr/local/nginx/conf/vhosts/default.conf
------------------------------
server {
server_name www.abc.com;
pagespeed on;
include ngx_pagespeed.inc;
location / {
index index.html index.php;
root /usr/local/nginx/html/www.abc.com;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/www.abc.com$fastcgi_script_name;
include fastcgi_params;
}
}
------------------------------
重启服务
# service nginx restart
3.验证ngx_pagespeed模块是否加载
# curl -I localhost | grep X-Page-Speed
注:显示X-Page-Speed: 1.6.29.5-3346说明加载成功
浏览器访问首页,查看JS源文件对比模块是否加载
------------大功告成---------------
更多CentOS相关信息见CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14
