Nginx itself it was a performance of web server works very well. However, there are ways to optimize more and one of them is to use the modules to be developed by Google called PageSpeed (ngx_pagespeed)
ngx_pagespeed
ngx_pagespeed speeds up your website and reduce the time to load dramatically by automatically applying the techniques to optimize page and static component such as CSS, Javascript, Image.
Some filter or by ngx_pagespeed:
Collapse Whitespace: reducing the bandwidth used by replacing multiple whitespace (whitespace) in HTML by a space only.
Canonicalize JavaScript Libraries: reducing the bandwidth used by automatically using popular Javascript libraries on the server free (e.g. Google).
Combine CSS: reduce the number of HTTP requests by combining multiple CSS files into one file.
Combine JavaScript: reduce the number of HTTP requests by combining multiple JavaSript file into a file.
Extend the Cache: reduce bandwidth usage by optimizing the function cache of the browser.
Flatten the CSS Imports: reduce the number of HTTP request by deleting @import in the CSS file.
Lazyload Images: slowing down the load of images not be displayed on the user’s browser.
Minify JavaScript: reducing the bandwidth used by the Javascript file size optimization.
Optimize Images: optimize images using inline images, compressed images, or convert GIF to PNG.
Pre-Resolve DNS: DNS resolution time decreased by resolution of DNS prior to using HTML.
And also a lot of filter and illustrative examples of the official site ngx_pagespeed.
We can not install ngx_pagespeed as a separate module that need to be installed by build Nginx from source code.
Build and install Nginx with ngx_pagespeed
-Prepare the ingredients needed to build nginx and ngx_pagespeed (need not perform if installed the HocVPS Script)
On Debian, Ubuntu or Linux Mint:
apt-get install build-essential zlib1g-dev libpcre3-dev
On Fedora, CentOS or RHEL:
yum install gcc-c ++-devel pcre zlib-devel make wget
-Download the ngx_pagespeed source code (latest release 1.8.31.4-beta) and unzip into the directory/usr/local/nginx/modules/
cd
NPS_VERSION = 1.8.31.4
mkdir-p/usr/local/nginx/modules
https://github.com/pagespeed/ngx_pagespeed/archive/release wget-$ {NPS_VERSION}-beta.tar.gz
tar xvfvz release-$ {NPS_VERSION}-beta.tar.gz-C/usr/local/nginx/modules–no-same-owner
-Download the PSOL (PageSpeed Optimization Libraries) and unzip into the directory ngx_pagespeed
wget https://dl.google.com/dl/page-speed/psol/$ {NPS_VERSION} .tar.gz
tar xvfvz $ {NPS_VERSION} .tar.gz-C/usr/local/nginx/modules/ngx_pagespeed-release-$ {NPS_VERSION}-beta–no-same-owner
find/usr/local/nginx/modules/ngx_pagespeed-release-$ {NPS_VERSION}-beta/-type d-exec chmod + rx {} \;
find/usr/local/nginx/modules/ngx_pagespeed-release-$ {NPS_VERSION}/-type f-beta-exec chmod + r {} \;
-Download the latest version of nginx and unzip into the directory/usr/local (need not perform if installed the HocVPS Script)
wget http://nginx.org/download/nginx-1.6.0.tar.gz
tar xvfvz nginx-1.6.0.tar.gz-C/usr/local–no-same-owner
-Finally, compile Nginx with module ngx_pagespeed and proceed with the installation
cd/usr/local/nginx-1.6.0
./configure–add-module =/usr/local/nginx/modules/ngx_pagespeed-release-$ {NPS_VERSION}-beta–prefix =/usr/share/nginx-/usr/sbin/nginx = path-sbin—with-http_ssl_module–conf-path =/etc/nginx/nginx.conf–with-http_gzip_static_module–with-http_realip_module–group = nginx–user = nginx-pid-path =/var/run/nginx.pid—with-http_stub_status_module
make
make install
Note: depending on the individual needs that you need to add more modules to compile Nginx with ngx_pagespeed.
-Restart Nginx
service nginx restart
-Check that the ngx_pagespeed module has been integrated into Nginx yet with the command
nginx-V
If you see similar results returned after it was installed successfully
nginx version nginx/1.6.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)
TLS SNI support enabled
configure arguments:–add-module =/usr/local/nginx/modules/ngx_pagespeed-release-1.8.31.4-beta-/usr/share/nginx = prefix—sbin-path =/usr/sbin/nginx–with-http_ssl_module–conf-path =/etc/nginx/nginx.conf–with-http_gzip_static_module–with-http_realip_module–group = nginx–user = nginx-pid-path =/var/run/nginx.pid—with-http_stub_status_module
Ngx_pagespeed module configuration
-Before proceeding with configuration, you need to create the directory cache module
mkdir/var/ngx_pagespeed_cache
chown nginx: nginx/var/ngx_pagespeed_cache
-To enable and configure the ngx_pagespeed, you need to edit the configuration file of the Nginx (/etc/nginx/nginx.conf).
ngx_pagespeed there are many different filter, depending on the purpose of use that your options accordingly. There are 2 different level you could use is CoreFilters
Leave a Reply