Ngx_pagespeed is an Nginx extension module that can accelerate your website and reduce page loading time, it automatically applies some practices for improving web performance to webpages and related resources such as CSS, JS, and images. You do not need to modify the content and process.
Features:
Image optimization: stripping meta-data, dynamic resizing, recompression
CSS & JavaScript compression and merge
Inline of small resources
Delay image and JS Loading
HTML Rewriting
Extend cache Extension
-----------------------------------------------
System Environment: CentOS6.3 x64
NGINX: nginx-1.4.1
Pagespeed: ngx_pagespeed-1.6.29.5
I. Deployment environment:
1. Disable iptables and SELINUX
# Service iptables stop
# Setenforce 0
# Vi/etc/sysconfig/selinux
---------------
SELINUX = disabled
---------------
2. Install the dependency package
# Yum install gcc-c ++ pcre-devel zlib-devel zip wget gcc-c ++ ncurses-devel cmake make perl bison openssl-devel gcc * libxml2 libxml2-devel curl-devel libjpeg * libpng * freetype *
3. Synchronization time
# Ntpdate asia.pool.ntp.org
2. Install ngx_pagespeed
1. Configure ngx_pagespeed
# Wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.6.29.5-beta.zip
# Unzip release-1.6.29.5-beta.zip
# Cd ngx_pagespeed-release-1.6.29.5-beta/
2. Configure the psol Module
# Wget https://dl.google.com/dl/page-speed/psol/1.6.29.5.tar.gz
# Tar-xzvf 1.6.29.5.tar.gz
3. Install nginx
1. Pre-installation Configuration
Add nginx users and user groups first
# Groupadd nginx
# Useradd-g nginx-s/bin/false-M nginx
2. decompress and compile the source code package. The latest source code package 1.4.1 is used here.
# Wget http://nginx.org/download/nginx-1.4.1.tar.gz
# Tar-xvzf nginx-1.4.1.tar.gz
# Cd nginx-1.4.1/
#. /Configure -- prefix =/usr/local/nginx -- pid-path =/var/run/nginx. pid -- lock-path =/var/lock/nginx. lock -- user = nginx -- group = nginx -- with-http_ssl_module -- with-http_dav_module -- with-http_flv_module -- with-http_realip_module -- with-http_gzip_static_module -- with-http_stub_status_module -- with-mail_ssl_module -- with-mail -- with-debug -- http-client-body-temp- path =/var/tmp/nginx/client -- http-proxy-temp-path =/var/tmp/nginx/proxy -- http-fastcgi-temp-path =/var/tmp /nginx/fastcgi -- http-uwsgi-temp-path =/var/tmp/nginx/uwsgi -- http-scgi-temp-path =/var/tmp/nginx/scgi -- add -module = $ HOME/ngx_pagespeed-release-1.6.29.5-beta
Note: -- add-module = $ HOME/ngx_pagespeed-release-1.6.29.5-beta is the ngx_pagespeed module loaded upon compilation
This will use the binary PageSpeed optimized library, but it may also be created from the source PSOL
Ngx_pagespeed currently does not support Windows or MacOS because it does not support the underlying PSOL library.
# Make & make install
Create cache directory
# Mkdir-p/var/tmp/nginx/client
3. Create a STARTUP script
# Vi/etc/init. d/nginx
-------------------------------
#! /Bin/sh
#
# Nginx-this script starts and stops the nginx daemin
#
# Chkconfig:-85 15
# Description: Nginx is an HTTP (S) server, HTTP (S) reverse \
# Proxy and IMAP/POP3 proxy server
# Processname: nginx
# Config:/usr/local/nginx/conf/nginx. conf
# Pidfile:/usr/local/nginx/logs/nginx. pid
# Source function library.
./Etc/rc. d/init. d/functions
# Source networking configuration.
./Etc/sysconfig/network
# Check that networking is up.
["$ NETWORKING" = "no"] & exit 0
Nginx = "/usr/local/nginx/sbin/nginx"
Prog = $ (basename $ nginx)
NGINX_CONF_FILE = "/usr/local/nginx/conf/nginx. conf"
Lockfile =/var/lock/subsys/nginx
Start (){
[-X $ nginx] | exit 5
[-F $ NGINX_CONF_FILE] | exit 6
Echo-n $ "Starting $ prog :"
Daemon $ nginx-c $ NGINX_CONF_FILE
Retval =$?
Echo
[$ Retval-eq 0] & touch $ lockfile
Return $ retval
}
Stop (){
Echo-n $ "Stopping $ prog :"
Killproc $ prog-QUIT
Retval =$?
Echo
[$ Retval-eq 0] & rm-f $ lockfile
Return $ retval
}
Restart (){
Configtest | return $?
Stop
Start
}
Reload (){
Configtest | return $?
Echo-n $ "Reloading $ prog :"
Killproc $ nginx-HUP
RETVAL =$?
Echo
}
Force_reload (){
Restart
}
Configtest (){
$ Nginx-t-c $ NGINX_CONF_FILE
}
Rh_status (){
Status $ prog
}
Rh_status_q (){
Rh_status>/dev/null 2> & 1
}
Case "$1" in
Start)
Rh_status_q & exit 0
$1
;;
Stop)
Rh_status_q | exit 0
$1
;;
Restart | configtest)
$1
;;
Reload)
Rh_status_q | exit 7
$1
;;
Force-reload)
Force_reload
;;
Status)
Rh_status
;;
Condrestart | try-restart)
Rh_status_q | exit 0
;;
*)
Echo $ "Usage: $0 {start | stop | status | restart | condrestart | try-restart | reload | force-
Reload | configtest }"
Exit 2
Esac
---------------------------
# Chmod 755/etc/init. d/nginx
# Chkconfig -- add nginx
# Service nginx start
# Chkconfig nginx on
4. Configure nginx to load the ngx_pagespeed Module
1. Create a pagespeed cache directory
# Mkdir/tmp/ngx_pagespeed_cache
# Chmod-R 777/tmp/ngx_pagespeed_cache
2. Configure nginx Loading
1) configure the nginx main configuration file
# Vi/usr/local/nginx/conf/nginx. conf
Add the following lines at the end of the http hierarchy:
-------------------------------------
# Cache path
Pagespeed FileCachePath/tmp/ngx_pagespeed_cache;
# Loading Module
Pagespeed on;
# Add a vhost configuration file
Include "/usr/local/nginx/conf/vhosts/*. conf ";
-------------------------------------
2) configure the ngx_pagespeed.inc Parameter
# 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). Configure 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;
}
}
------------------------------
Restart service
# Service nginx restart
3. Verify that the ngx_pagespeed module is loaded
# Curl-I localhost | grep X-Page-Speed
650) this. width = 650; "src =" http://img1.51cto.com/attachment/201309/170204382.jpg "title =" 1.jpg"/>
NOTE: If X-Page-Speed: 1.6.29.5-3346 is displayed, the loading is successful.
Visit the homepage to check whether the JS source file comparison module is loaded.
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/154051A02-1.jpg "style =" float: none; "title =" 2.jpg"/>
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1540515234-2.jpg "style =" float: none; "title =" 3.jpg"/>
------------ Success ---------------
This article from "all the way to the North" blog, please be sure to keep this source http://showerlee.blog.51cto.com/2047005/1287148