CentOS6 Nginx Enable Ngx_pagespeed accelerated site Access Tutorial

Source: Internet
Author: User
Tags http request openssl passthrough zip

1. Functional characteristics of Pagespeed

The Pagespeed module can use a large number of rewrite "filters", each of which can be selectively turned on/off to automate a variety of optimizations (such as reducing document size, reducing HTTP request data, reducing HTTP round-trip times, and shortening DNS resolution time).

Below are some of the filters supported by Ngx_pagespeed. Please refer to the official documentation for all the filters supported.

Collapse whitespace (compressed blank): Reduce bandwidth usage by replacing multiple consecutive blanks in HTML pages with a blank space.
Canonicalize JavaScript libraries (normalized transform JavaScript Library): Reduces bandwidth usage by automatically swapping popular JavaScript libraries for free, hosted JavaScript libraries, such as hosted by Google.
Combine css (merge CSS): Reduce the number of HTTP requests by merging multiple CSS files into a single CSS file.
Combine JavaScript (merge JavaScript): Reduces the number of HTTP requests by merging multiple JavaScript files into a single JavaScript file.
Elide Attributes (omitted attribute): Reduces the size of the document by removing the label specified by the default property.
Extend cache (Extended caching): Reduce bandwidth usage by optimizing the caching of Web page resources.
Flatten CSS Imports (thin CSS Import): Reduces the number of HTTP request round-trip trips by removing @import from the CSS file.
Lazyload Images (Delay loading picture): Delay loading the invisible picture on the client browser.
Minify JavaScript (shrink JavaScript): Reduces the amount of bandwidth usage by reducing JavaScript.
Optimize Images (optimized picture): Optimize distribution by introducing more inline images, compressing pictures, or converting GIF images into PNG images.
Pre-resolve DNS (pre-resolved DNS): Reduces DNS resolution time by resolving DNS.
Prioritize Critical CSS (optimize load key CSS rules): Rewrite the CSS file so that the CSS rules for the rendered page are loaded first.

2, download decompression pagespeed module
Scientific Linux 6 provides gcc-4.8 packages that work on CentOS 6.
sudo rpm--import Https://linux.web.cern.ch/linux/scientific6/docs/repository/cern/slc6X/i386/RPM-GPG-KEY-cern
sudo wget-o/etc/yum.repos.d/slc6-devtoolset.repo https://linux.web.cern.ch/linux/scientific6/docs/repository/ Cern/devtoolset/slc6-devtoolset.repo
sudo yum install devtoolset-2-gcc-c++ devtoolset-2-binutils

cd/usr/local/src/
wget Https://github.com/pagespeed/ngx_pagespeed/archive/release-1.11.33.3-beta.zip
Unzip-q Release-1.11.33.3-beta.zip
wget https://dl.google.com/dl/page-speed/psol/1.11.33.3.tar.gz
Tar xzf 1.11.33.3.tar.gz-c Ngx_pagespeed-release-1.11.33.3-beta #解压出来的psol文件夹到上面ngx_ Within the Pagespeed-release-1.11.33.3-beta folder

3, then to the Nginx source directory, add the following code to recompile Nginx
./configure--prefix=/usr/local/nginx--user=www--group=www\
-- Add-module=/root/ngx_http_google_filter_module \
--add-module=/root/ngx_http_substitutions_filter_module \
--add-module=/root/ngx_pagespeed-release-1.11.33.3-beta \
--with-cc=/opt/rh/devtoolset-2/root/usr/bin/ GCC \
--with-openssl=/root/openssl \
--with-pcre=/root/pcre \
--with-zlib=/root/zlib \
--with-http_ Stub_status_module \
--with-http_secure_link_module \
--with-http_v2_module \
--with-http_ssl_module \
--with-ipv6 \
--with-http_gzip_static_module \
--with-http_realip_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_sub_module \
--with-stream \
--with-stream_ssl_module
make// You do not need to install make install
/etc/init.d/nginx stop
CD objs/
CP nginx/usr/local/nginx/sbin//overwrite original file
/etc/init.d/ng Inx start

4, configure the Ngx_pagespeed module in Nginx
Pagespeed filters, there are two different levels you can choose from: Corefilters and Passthrough. Unless specified, corefilters is used by default.
Using Corefilters

server {
# Ports listening on
Listen 80;
# server Name
server_name www.zhangfangzhou.cn;
# Write down the root directory
root/usr/local/nginx/html;
# Access Log
Access_log/var/log/nginx/access.log main;
# Enable Ngx_pagespeed
Pagespeed on;
Pagespeed Filecachepath/var/ngx_pagespeed_cache;
# Enable Corefilters
Pagespeed Rewritelevel corefilters;
# Disable some filters in the Corefilters
Pagespeed disablefilters rewrite_images;
# Selectively enable additional filters
Pagespeed enablefilters Collapse_whitespace;
Pagespeed enablefilters lazyload_images;
Pagespeed enablefilters Insert_dns_prefetch;
}

For advanced users: Using Passthrough

server {
# Ports listening on
Listen 80;
# server Name
server_name www.zhangfangzhou.cn;
# Write down the root directory
root/usr/local/nginx/html;
# Access Log
Access_log/var/log/nginx/access.log main;
# Enable Ngx_pagespeed
Pagespeed on;
Pagespeed Filecachepath/var/ngx_pagespeed_cache;
# Disable Corefilters
Pagespeed Rewritelevel passthrough;
# Enable compressed blank filter
Pagespeed enablefilters Collapse_whitespace;
# Enable JavaScript Library Uninstall
Pagespeed enablefilters canonicalize_javascript_libraries;
# Combine multiple CSS files into a single CSS file
Pagespeed enablefilters combine_css;
# merge multiple JavaScript files into a JavaScript file
Pagespeed enablefilters Combine_javascript;
# Delete labels with default attributes
Pagespeed enablefilters elide_attributes;
# Improve the caching of resources
Pagespeed enablefilters Extend_cache;
# Replace the @import of the imported file, simplify the CSS file
Pagespeed enablefilters Flatten_css_imports;
Pagespeed cssflattenmaxbytes 5120;
# Delay Loading client unseen picture
Pagespeed enablefilters lazyload_images;
# Enable JavaScript shrink mechanism
Pagespeed enablefilters Rewrite_javascript;
# Enable picture optimization mechanism
Pagespeed enablefilters rewrite_images;
# Pre-resolved DNS query
Pagespeed enablefilters Insert_dns_prefetch;
# rewrite CSS, first load the CSS rules for rendering page
Pagespeed enablefilters prioritize_critical_css;
}

5, set up the cache folder and give Nginx user rights

sudo mkdir/var/ngx_pagespeed_cache
sudo chown Www:www/var/ngx_pagespeed_cache

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.