Nginx Compile and install Pagespeed optimize website access speed

Source: Internet
Author: User
Tags passthrough zip

As an nginx component, Nginx_pagespeed will rewrite your Web page to allow users to access it at a faster speed. The work of rewriting includes compressing pictures, reducing CSS and JavaScript, extending cache time, and also including some best practices:

Optimize caching-consolidate application data and logic

Minimize request overhead--Reduce upload size

Minimize load size--reduce response, download, and cache page size

Optimize browser rendering-improve browser page layout

Mobile optimization--Optimizing Site mobile network and device related features


Download Pagespeed module (installed nginx) Download address

# CD/USR/LOCAL/SRC
<pre name= "code" class= "HTML" ># wget https://github.com/pagespeed/ngx_pagespeed/archive/master.zip

Unzip the file into the SRC directory (zip with less, no command line, directly under the graphical interface operation)

# <span style= "font-family:arial, Helvetica, Sans-serif;" >cd/usr/local/src/ngx_pagespeed-master</span>
<span style= "font-family:arial, Helvetica, Sans-serif;" ></span><pre name= "code" class= "HTML" style= "FONT-SIZE:14PX;" ><span style= "font-family:arial, Helvetica, Sans-serif;" ># </span><span style= "font-family:arial, Helvetica, Sans-serif;" >wget https://dl.google.com/dl/page-speed/psol/1.9.32.3.tar.gz</span><pre name= "code" class= "plain" ><pre name= "code" class= "HTML" style= "FONT-SIZE:14PX;" ><pre name= "code" class= "HTML" style= "FONT-SIZE:14PX;" ><span style= "font-family:arial, Helvetica, Sans-serif;" ># </span><span style= "font-family:arial, Helvetica, Sans-serif;" >TAR-XZVF 1.9.32.3.tar.gz # expands to psol/</span>


Compiling the installation

CD nginx-1.7.1
 /usr/local/nginx/sbin/nginx-v # (copy previous configuration parameters)

./configure--with-http_secure_link_module-- With-http_stub_status_module--add-module=. /nginx-http-concat-master--add-module=. /ngx_pagespeed-master
make
 Mv/usr/local/nginx/sbin/nginx/usr/local/nginx/sbin/nginx-20150422.bak # Back up the last Nginx run file
cp Objs/nginx  



After this method is installed, the formal configuration of Nginx is started, first, in the configuration file (nginx.conf) of the server configuration block to join this session:

		<span style= "White-space:pre" > </span> #google pagespeed Tools <span style= "White-space:pre" > </span
>pagespeed on; <span style= "White-space:pre" > </span> <span style= "White-space:pre" > </span># Needs to exist and is writable by Nginx.  use TMPFS for best performance. File cache path <span style= "White-space:pre" > </span>pagespeed filecachepath/usr/local/nginx/ngx_pagespeed_
Cache    <span style= "White-space:pre" > </span> <span style= "White-space:pre" > </span> <span style= "White-space:pre" > </span># enable corefilters  <span style= "White-space:pre" > </span>pa Gespeed rewritelevel corefilters;  <span style= "White-space:pre" > </span># Disable some filters in CoreFilters and


nbsp <span style= "White-space:pre" > </span>pagespeed disablefilters rewrite_images;  <span style= " White-space:pre "> </span># selectively enable additional filters   <span Style= "White-space:pre" > </span>pagespeed enablefilters collapse_whitespace;  <span style= " White-space:pre "> </span>pagespeed enablefilters lazyload_images;  <span style=" White-space:pre " > </span>pagespeed enablefilters insert_dns_prefetch;  <span style= "White-space:pre" > </span&
Gt <span style= "White-space:pre" > </span># ensure requests for pagespeed optimized resources go to the Pagespee
D handler <span style= "White-space:pre" > </span># and no extraneous headers get set. <span style= "White-space:pre" > </span>location ~ "\.pagespeed\. ([A-z]\.)? [A-z] {2}\. [^.] {10}\. [^.]
+ "{  <span style=" White-space:pre "> </span>add_header" "" "; <span style= "White-space:pre" > </span>} <span style= "White-space:pre" > </span>location ~ "^/p agespeed_static/"{} <span style=" White-space:pre "> </span>location ~" ^/ngx_pagespeed_beacon$ "{}<span style= "White-space:pre" > </span> 


------------------------------------------------------------------------------------Divider Line---------------------------------- ------------------------------------------------------------------------------------------------------

A simple understanding of the configuration file:

Pagespeed Rewritelevel PassThrough;

Pagespeed offers 3 kinds of "levels" to configure simplification: PassThrough, corefilters, and Optimizeforbandwidth. Corefilters contains a series of pagespeed filters that Google believes are safe for most websites. If you enable Corefilters, you automatically enable a series of "security" rules. Therefore, it is recommended for novice users to use this method. If you prefer, you can also disable some or some of the filters in Corefilters, or selectively enable additional filters. The following example shows the Ngx_pagespeed configuration using Corefilters.

server { 

  # listening port 

 listen; 

 # server name 

 server_name xmodulo.com www.xmodulo.com; 

 # Note The root directory 

 root/usr/local/nginx/html; 

 # Access log 

 Access_log/var/log/nginx/access.log main; 

# Enable Ngx_pagespeed 

pagespeed on; 
<pre name= "code" class= "plain" >
#缓存文件路径
pagespeed filecachepath/usr/local/nginx/ngx_pagespeed_ Cache;

# Enable Corefilters 
pagespeed rewritelevel corefilters; 

# Disable some filters in corefilters
 pagespeed disablefilters rewrite_images; 

# selectively enable additional filters 
pagespeed enablefilters collapse_whitespace; 
Pagespeed enablefilters lazyload_images; 
Pagespeed enablefilters insert_dns_prefetch;

 }


To learn about all the filters in Corefilters, see the official documentation.







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.