CentOS System Configuration Pagespeed Compressed Site page (css,js,html)

Source: Internet
Author: User
Tags pack zip centos

Pagespeed is an open source project, the project in Github Open Source address is: https://github.com/pagespeed/ngx_pagespeed

Pagespeed can compress the static resources (CSS, JS, pictures, etc.) on your site to speed up the loading of the user's Web pages.

Pagespeed support Apache, Nginx.

In this paper, we take Nginx as an example for pagespeed configuration. A three-step process:

1. Install GCC and other dependent libraries

Please follow your system type.

The code is as follows Copy Code

Redhat, CentOS, Fedora:

$ sudo yum install gcc-c++ pcre-dev pcre-devel zlib-devel make
Debian, Ubuntu:

$ sudo apt-get install build-essential zlib1g-dev libpcre3 Libpcre3-dev

2. Download Ngx_pagespeed

The code is as follows Copy Code
$ cd ~ # back to user directory
$ wget https://github.com/pagespeed/ngx_pagespeed/archive/v1.8.31.4-beta.zip # download Ngx_pagespeed Source Pack
$ unzip V1.8.31.4-beta.zip # Unzip the compressed package just downloaded
$ cd ngx_pagespeed-1.8.31.4-beta/# cut to unzip directory
$ wget https://dl.google.com/dl/page-speed/psol/1.8.31.4.tar.gz # download Psol
$ TAR-XZVF 1.8.31.4.tar.gz # expands to psol/# extract Psol

3. Configure to Nginx

The code is as follows Copy Code
$ cd ~ # back to user directory
$ wget http://nginx.org/download/nginx-1.6.0.tar.gz #下载 nginx Source Pack
$ tar-xvzf nginx-1.6.0.tar.gz #解压 nginx Source Pack
$ cd nginx-1.6.0/# cut to unzip directory
$./configure--add-module= $HOME/ngx_pagespeed-1.8.31.4-beta #添加 Nginx module: pagespeed

$ make # Compile Nginx
Please choose the following according to your situation
1 If you are newly installed Nginx, perform:

$ sudo make install
2 If you have previously installed Nginx, perform (below Nginx directory please replace according to your actual situation, such as:/usr/bin/nginx):

The code is as follows Copy Code
$ Cp/usr/sbin/nginx/usr/sbin/nginx.bak # backup Nginx file, safekeeping
$ CP objs/nginx/usr/sbin/

Now that you have configured the Pagespeed module into Nginx, add pagespeed support for your site:

Edit/usr/local/nginx/conf/nginx.conf (Please select directories and files according to the actual situation), add in the server block:

The code is as follows Copy Code
Pagespeed on;
Pagespeed Filecachepath/var/ngx_pagespeed_cache;
Location ~ "\.pagespeed\. ([A-z]\.)? [A-z] {2}\.[^.] {10}\.[^.] + "{add_header" "" ";}
Location ~ "^/pagespeed_static/" {}
Location ~ "^/ngx_pagespeed_beacon$" {}

Note that if you have more than one virtual host, you need to add the above code to each host's configuration file separately.

Then test that the configuration file is passed, below (the Nginx directory below, please replace according to your actual situation, such as:/usr/bin/nginx):

The code is as follows Copy Code
$ sudo/usr/sbin/nginx-t # Test configuration file

If you see:

The code is as follows Copy Code
Nginx:the configuration file/etc/nginx/nginx.conf syntax is OK
Nginx:configuration file/etc/nginx/nginx.conf Test is successful

This means that the configuration passes, or else the upgrade code is executed:

The code is as follows Copy Code
$ sudo make upgrade

Finally reboot the Nginx to complete the configuration.

Related Article

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.