VPS配置:
Ubuntu 14.04 x86
RAM 512M
SWAP 64M
DISK 5G
准备工作
sudo apt-get update&&apt-get upgrade -y
sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev unzip libssl-dev -y
下载ngx_pagespeed
cd
NPS_VERSION=1.9.32.4
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.zip
unzip release-${NPS_VERSION}-beta.zip
cd ngx_pagespeed-release-${NPS_VERSION}-beta/
wget https://dl.google.com/dl/page-speed/psol/${NPS_VERSION}.tar.gz
tar -xzvf ${NPS_VERSION}.tar.gz
安装Nginx
cd
groupadd www
useradd -s /sbin/nologin -g www www
NGINX_VERSION=1.8.0
wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz
tar -xvzf nginx-${NGINX_VERSION}.tar.gz
cd nginx-${NGINX_VERSION}/
./configure \
--user=www \
--group=www \
--prefix=/usr/local/nginx \
--with-http_stub_status_module \
--with-http_ssl_module \
--with-http_spdy_module \
--with-http_gzip_static_module \
--with-http_sub_module \
--add-module=$HOME/ngx_pagespeed-release-${NPS_VERSION}-beta \
sudo make
sudo make install
sudo ln -sf /usr/local/nginx/sbin/nginx /usr/bin/nginx
配置/etc/init.d/nginx
sudo wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu/master/nginx -O /etc/init.d/nginx
sudo chmod +x /etc/init.d/nginx
管理Nginx服务
service nginx {start|stop|restart|force-reload|reload|status|configtest|quietupgrade|terminate|destroy}
测试安装结果
root@bwgvps:~# 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
配置ngx_pagespeed
编辑Nginx的配置文件(/usr/local/nginx/conf/nginx.conf)
在server段内添加include gp.conf
在/usr/local/nginx/conf/
内新建gp.conf
,内容如下:
pagespeed on;
pagespeed FileCachePath /usr/local/nginx/pagespeed/;
pagespeed RewriteLevel PassThrough;
pagespeed EnableFilters collapse_whitespace;
pagespeed EnableFilters canonicalize_javascript_libraries;
pagespeed EnableFilters combine_css;
pagespeed EnableFilters combine_javascript;
pagespeed EnableFilters elide_attributes;
pagespeed EnableFilters extend_cache;
pagespeed EnableFilters flatten_css_imports;
pagespeed CssFlattenMaxBytes 5120;
pagespeed EnableFilters lazyload_images;
pagespeed EnableFilters rewrite_javascript;
pagespeed EnableFilters rewrite_images;
pagespeed EnableFilters insert_dns_prefetch;
pagespeed EnableFilters prioritize_critical_css;
Nginx reload后,用curl
验证是否开启
root@bwgvps:~# curl -I 127.0.0.1
HTTP/1.1 200 OK
Server: nginx/1.8.0
Content-Type: text/html
Connection: keep-alive
Date: Sat, 07 Feb 1970 00:54:49 GMT
X-Page-Speed: 1.9.32.4-7251
Cache-Control: max-age=0, no-cache
以上X-Page-Speed代表已经OK!
参考: