NGINX with PageSpeed Module: Installation and Configuration
- Posted in:
- NGINX
- Installation
- PageSpeed
- Server
To optimize the performance of our discoverize portals we decided to try out the PageSpeed Module. Since we already have a little experience with NGINX, we decided to install NGINX(version 1.8.0) with the PageSpeed Module (version 1.9.32.10) on our CentOS 6 and CentOS 7 servers.
Installation:
- use guide: https://developers.google.com/speed/pagespeed/module/build_ngx_pagespeed_from_source
- ngx_pagespeed was not saved as .zip file, but without file extension – adjust the unzip command accordingly
- if needed add other modules to the NGINX configuration before installing NGINX, for instance the ngx_http_ssl_module:
./configure --add-module=$HOME/ngx_pagespeed-release-${NPS_VERSION}-beta --with-http_ssl_module
- If you install with the http_ssl_module you may have to install OpenSSL libraries first. yum install openssl will probably not suffice, yum install openssl-devel will be needed (you may wonder why ./configure states that OpenSSL is not available even though it is installed – what it really needs is openssl-devel).
- if only over-installing nginx, do not forget to restart the nginx service (reload will do nothing)
- create NGINX init script: https://www.nginx.com/resources/wiki/start/topics/examples/redhatnginxinit/
- adjust folder paths in that script:
- nginx="/usr/local/nginx/sbin/nginx" (line 22)
- NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" (line 25)
- give init script sufficient rights: rwxr-xr-x
- create log rotation script: http://www.scalescale.com/tips/nginx/how-to-rotate-nginx-logs/
Uninstall:
There is no uninstall parameter in make for NGINX. Just remove the folders and files: sudo rm -f -R /usr/local/nginx && rm -f /usr/local/sbin/nginx && rm -rf /etc/init.d/nginx
Configuration:
- configure NGINX as proxy for web site
- there are many guides out there, for instance: https://www.nginx.com/resources/admin-guide/reverse-proxy/
- proxy_set_header has to be set, so backend server knows which application should reply
- proxy_http_version has to be set to 1.1 – otherwise only parts of page may be transferred
- enable the module: https://developers.google.com/speed/pagespeed/module/configuration
- use tmpfs for the caching folder: https://developers.google.com/speed/pagespeed/module/faq#tmpfs
- configure filters for PageSpeed Module: https://developers.google.com/speed/pagespeed/module/config_filters
let PageSpeed take care of compressing the response: do not activate gzip, PageSpeed will automatically configure it
try out the filters which are not automatically enabled with the RewriteLevel CoreFilters
All in all it is not an easy task to get the PageSpeed Module working, but in the end it is surely easier and faster to let it optimize your web site responses instead of implementing all the different optimizations.
Since our backend server are Windows server we briefly considered using the IISpeed wrapper for the PageSpeed Module, but went with NGINX. Maybe IISpeed is easier to install and to configure. If you have experience using IISpeed, I would like to read a comment about ist usability.