For those of you who didn’t know,
PageSpeed (ngx_pagespeed) is a Nginx module created by Google to help
Make the Web Faster by rewriting web pages to reduce latency and
bandwidth. For the installation, we will need to compile nginx from
souce with the PageSpeed module, as Nginx doesn’t support Dynamic module
loading (DSO), unless you want to build your own rpm or deb files. This
article assumes you have at least basic knowledge of linux, know how to
use the shell, and most importantly, you host your site on your own
VPS.
Install Nginx With ngx_pagespeed on CentOS
Step 1. Install dependencies
|
yum install gcc-c++ pcre-devel pcre-devel zlib-devel make unzip openssl-devel
|
Step 2. Download and install ngx_pagespeed and
PSOL (PageSpeed Optimization Libraries) source code as follows.
|
mkdir -p /opt/nginx/modules
cd /opt/nginx/modules
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.7.30.3-beta.zip
unzip release-1.7.30.3-beta.zip
cd ngx_pagespeed-release-1.7.30.3-beta/
wget https://dl.google.com/dl/page-speed/psol/1.7.30.3.tar.gz
tar -xzf 1.7.30.3.tar.gz
|
Step 3. Download the latest stable version of Nginx from
here and build it with ngx_pagespeed support.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
## cd /opt/nginx/
## wget http://nginx.org/download/nginx-1.6.2.tar.gz
## tar -zxf nginx-1.6.2.tar.gz
## cd nginx-1.6.2/
## ./configure --add-module=/opt/nginx/modules/ngx_pagespeed-release-1.7.30.3-beta \
--prefix=/usr/local/nginx \
--sbin-path=/usr/local/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/run/nginx.pid \
--lock-path=/run/lock/subsys/nginx \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--without-mail_pop3_module \
--without-mail_imap_module \
--without-mail_smtp_module \
--user=nginx \
--group=nginx
## make
## make install
|
Step 4. You can verify that ngx_pagespeed module has been added to Nginx installation using the following command
|
nginx version: nginx/1.6.2
built by gcc 4.8.2 20131212 (Red Hat 4.8.2-7) (GCC)
configure arguments: --add-module=/usr/local/nginx/modules/ngx_pagespeed-1.7.30.3-beta . . . .
|
Step 5. Configure ngx_pagespeed module in
Nginx
|
nano /etc/nginx/nginx.conf
...
# enable ngx_pagespeed
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
...
|
Step 6. Create a file cache directory which will be written by Nginx.
|
mkdir /var/ngx_pagespeed_cache
chown nginx:nginx /var/ngx_pagespeed_cache
|
Step 7. Create an init script for Nginx.
|
wget -O /etc/init.d/nginx https://raw.githubusercontent.com/Fleshgrinder/nginx-sysvinit-script/master/nginx
chmod 0755 /etc/init.d/nginx
chown root:root /etc/init.d/nginx
|
Step 8. Finally, start Nginx.
Congratulation’s! You have successfully
installed Nginx with ngx_pagespeed. Thanks for using this tutorial for
installing Nginx with ngx_pagespeed on CentOS system. For additional
help or useful information, we recommend you to check the official Nginx
web site.
Комментариев нет:
Отправить комментарий