- Joined
- May 20, 2016
- Messages
- 149
- Points
- 28
Nginx itself is a web server with very good performance. However there are ways to optimize more and one of them is using the module developed by Google called PageSpeed (ngx_pagespeed)
ngx_pagespeed help your website improve the speed and reduced load time by automatically applying optimized engineering components and static page such as CSS, JavaScript, Image.
Some filters of ngx_pagespeed:
Collapse Whitespace: reduce bandwidth usage by replacing multiple blanks in HTML by 1 space only.
Canonicalize JavaScript Libraries: reduce bandwidth usage by automatically using the popular Javascript library on free servers (eg, Google).
Combine CSS: reducing the number of HTTP requests by combining multiple CSS files into one file.
Combine JavaScript: reducing the number of HTTP requests using a combination of JavaScript files into one file.
Extend Cache: reduce bandwidth usage by optimizing the function of the browser cache.
Flatten CSS Imports: reducing the number of HTTP requests by deleting @import CSS file.
Lazyload Images: slowing down the loading of images are not displayed on the user's browser.
JavaScript minify: reduce bandwidth usage by optimizing the JavaScript file size.
Optimize Images: optimize images using inline images, image compression, or convert GIF to PNG.
Pre-Resolve DNS: DNS resolution time decreased by DNS pre-resolution using HTML.
And there are many filters and other examples of ngx_pagespeed on official page.
We can not install ngx_pagespeed as an individual module that needs to install by build Nginx from source code.
Build and install Nginx with ngx_pagespeed
- Prepare the needed ingredients to build nginx and ngx_pagespeed
On Debian, Ubuntu or Linux Mint:
On Fedora, CentOS or RHEL:
- Download source ngx_pagespeed (latest 1.8.31.4-beta) and unzip into the directory /usr/local/nginx/modules/
- Download PSOL (PageSpeed Optimization Libraries) and unzip into the directory ngx_pagespeed
- Download the latest nginx and unzip into the directory /usr/local
- Finally, compile Nginx with module ngx_pagespeed and starting the installation
Note: depending on your needs that adding the module to compile Nginx with ngx_pagespeed.
- Restart Nginx
- Check that the module has been integrated into ngx_pagespeed Nginx with the command
If you see returned results similar to this then it was successful.
Configuration module ngx_pagespeed
- Prior to the configuration, you need to create the cache directory for the module
- To enable and configure ngx_pagespeed, you need to edit the configuration file of Nginx (/etc/nginx/nginx.conf).
ngx_pagespeed have more different filters, depending on the different uses that you have appropriate choices. There are two different filters that you can use is CoreFilters (by default) and passthrough.
CoreFilters
CoreFilters is a set of Google-certified filter is safe for most websites. Therefore, this way you fit the new newbie try. If needed, you can disable a filter from any other CoreFilters or add a filter to.
This is an example configuration with CoreFilters ngx_pagespeed:
See full list of filters available in CoreFilters here.
Passthrough
With the knowledge you already have, you should use the experience passthrough. When it will have to activate the filter to be used.
Configuration example with passthrough:
Restart web server for the changes to take effect
ngx_pagespeed with memcache, Opcache Zend is one of its modules to encourage people to use and I would recommend to install them on your host.
Good luck!
ngx_pagespeed help your website improve the speed and reduced load time by automatically applying optimized engineering components and static page such as CSS, JavaScript, Image.
Some filters of ngx_pagespeed:
Collapse Whitespace: reduce bandwidth usage by replacing multiple blanks in HTML by 1 space only.
Canonicalize JavaScript Libraries: reduce bandwidth usage by automatically using the popular Javascript library on free servers (eg, Google).
Combine CSS: reducing the number of HTTP requests by combining multiple CSS files into one file.
Combine JavaScript: reducing the number of HTTP requests using a combination of JavaScript files into one file.
Extend Cache: reduce bandwidth usage by optimizing the function of the browser cache.
Flatten CSS Imports: reducing the number of HTTP requests by deleting @import CSS file.
Lazyload Images: slowing down the loading of images are not displayed on the user's browser.
JavaScript minify: reduce bandwidth usage by optimizing the JavaScript file size.
Optimize Images: optimize images using inline images, image compression, or convert GIF to PNG.
Pre-Resolve DNS: DNS resolution time decreased by DNS pre-resolution using HTML.
And there are many filters and other examples of ngx_pagespeed on official page.
We can not install ngx_pagespeed as an individual module that needs to install by build Nginx from source code.
Build and install Nginx with ngx_pagespeed
- Prepare the needed ingredients to build nginx and ngx_pagespeed
On Debian, Ubuntu or Linux Mint:
Code:
apt-get install build-essential zlib1g-dev libpcre3-dev
Code:
yum install gcc-c++ pcre-devel zlib-devel make wget
Code:
cd
NPS_VERSION=1.8.31.4
mkdir -p /usr/local/nginx/modules
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-${NPS_VERSION}-beta.tar.gz
tar xvfvz release-${NPS_VERSION}-beta.tar.gz -C /usr/local/nginx/modules --no-same-owner
- Download PSOL (PageSpeed Optimization Libraries) and unzip into the directory ngx_pagespeed
Code:
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}-beta/ -type f -exec chmod +r {} \;
Code:
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
Code:
cd /usr/local/nginx-1.6.0
./configure --add-module=/usr/local/nginx/modules/ngx_pagespeed-release-${NPS_VERSION}-beta --prefix=/usr/share/nginx --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
make
make install
- Restart Nginx
Code:
service nginx restart
Code:
nginx -V
Code:
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 --prefix=/usr/share/nginx --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
Configuration module ngx_pagespeed
- Prior to the configuration, you need to create the cache directory for the module
Code:
mkdir /var/ngx_pagespeed_cache
chown nginx:nginx /var/ngx_pagespeed_cache
ngx_pagespeed have more different filters, depending on the different uses that you have appropriate choices. There are two different filters that you can use is CoreFilters (by default) and passthrough.
CoreFilters
CoreFilters is a set of Google-certified filter is safe for most websites. Therefore, this way you fit the new newbie try. If needed, you can disable a filter from any other CoreFilters or add a filter to.
This is an example configuration with CoreFilters ngx_pagespeed:
Code:
server {
listen 80 forumweb.hosting;
access_log off;
error_log off;
# error_log /home/forumweb.hosting/logs/error.log;
root /home/forumweb.hosting/public_html;
index index.php index.html index.htm;
server_name forumweb.hosting;
# enable ngx_pagespeed
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# let's speed up PageSpeed by storing it in the super duper fast memcached
# pagespeed MemcachedThreads 1;
# pagespeed MemcachedServers "localhost:11211";
# enable CoreFilters
[COLOR="#FF8C00"]pagespeed RewriteLevel CoreFilters[/COLOR];
# disable particular filter(s) in CoreFilters
pagespeed DisableFilters rewrite_images;
# enable additional filter(s) selectively
pagespeed EnableFilters collapse_whitespace;
pagespeed EnableFilters lazyload_images;
pagespeed EnableFilters insert_dns_prefetch;
}
Passthrough
With the knowledge you already have, you should use the experience passthrough. When it will have to activate the filter to be used.
Configuration example with passthrough:
Code:
server {
listen 80 forumweb.hosting;
access_log off;
error_log off;
# error_log /home/forumweb.hosting/logs/error.log;
root /home/forumweb.hosting/public_html;
index index.php index.html index.htm;
server_name forumweb.hosting;
# enable ngx_pagespeed
pagespeed on;
pagespeed FileCachePath /var/ngx_pagespeed_cache;
# let's speed up PageSpeed by storing it in the super duper fast memcached
# pagespeed MemcachedThreads 1;
# pagespeed MemcachedServers "localhost:11211";
# disable CoreFilters
pagespeed RewriteLevel [COLOR="#FF8C00"]PassThrough[/COLOR];
# enable collapse whitespace filter
pagespeed EnableFilters collapse_whitespace;
# enable JavaScript library offload
pagespeed EnableFilters canonicalize_javascript_libraries;
# combine multiple CSS files into one
pagespeed EnableFilters combine_css;
# combine multiple JavaScript files into one
pagespeed EnableFilters combine_javascript;
# remove tags with default attributes
pagespeed EnableFilters elide_attributes;
# improve resource cacheability
pagespeed EnableFilters extend_cache;
# flatten CSS files by replacing @import with the imported file
pagespeed EnableFilters flatten_css_imports;
pagespeed CssFlattenMaxBytes 5120;
# defer the loading of images which are not visible to the client
pagespeed EnableFilters lazyload_images;
# enable JavaScript minification
pagespeed EnableFilters rewrite_javascript;
# enable image optimization
pagespeed EnableFilters rewrite_images;
# pre-solve DNS lookup
pagespeed EnableFilters insert_dns_prefetch;
# rewrite CSS to load page-rendering CSS rules first.
pagespeed EnableFilters prioritize_critical_css;
}
Code:
[COLOR="#FF8C00"][/COLOR]]nginx service restart
Good luck!