Latest News

Build Nginx with PageSpeed, Brotli, OpenSSL from Source

  • Ivan Ivanov
  • Nginx
Build Nginx with PageSpeed, Brotli, OpenSSL from Source

PageSpeed is a set of modules for NGINX and Apache which optimize and measure page performance of websites. Optimization is done by minifying static assets such as CSS and JavaScript, which decreases page load time. PageSpeed Insights is a tool that measures your site’s performance, and makes recommendations for further modifications based on the results.

Brotli is a generic-purpose lossless compression algorithm that compresses data using a combination of a modern variant of the LZ77 algorithm, Huffman coding and 2nd order context modeling, with a compression ratio comparable to the best currently available general-purpose compression methods. It is similar in speed with deflate but offers more dense compression.

headers-more-nginx-module - Set, Add and Clear Arbitrary Output Headers in NGINX HTTP Servers.
OpenSSL
ngx_brotli

We execute below command lines one by one and after "bash <(curl -f -L -sS https://ngxpagespeed.com/install) \ --nginx-version latest" we will get asked if we want to add any extra Nginx Modules and that is where we select yes and add the "./configure \" part.


wget https://www.openssl.org/source/openssl-1.1.1b.tar.gz -O - | tar -xz
wget http://zlib.net/zlib-1.2.11.tar.gz -O - | tar -xz

git clone https://github.com/google/ngx_brotli.git
cd ngx_brotli && git submodule update --init

wget https://github.com/openresty/headers-more-nginx-module/archive/v0.33.tar.gz -O - | tar -xz


bash <(curl -f -L -sS https://ngxpagespeed.com/install) \
--nginx-version latest

./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/run/nginx.pid \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--user=nginx \
--group=nginx \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-zlib=/home/zlib-1.2.11 \
--with-http_realip_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_stub_status_module \
--add-module=/home/headers-more-nginx-module-0.33 \
--add-module=/home/openssl-1.1.1b \
--add-module=/home/ngx_brotli

Lastly in /etc/nginx/nginx.conf we add below to Activate PageSpeed & Brotli.


# PageSpeed Configuration
pagespeed on;
pagespeed FileCachePath /var/cache/nginx/pagespeed;
pagespeed RewriteLevel CoreFilters;
pagespeed DisableFilters rewrite_images;
pagespeed EnableFilters collapse_whitespace,lazyload_images,insert_dns_prefetch;

brotli on;
brotli_min_length 1000;
brotli_comp_level 5;
brotli_types text/plain
text/css
text/xml
application/javascript
application/x-javascript
application/xml
application/xml+rss
application/ecmascript
application/json i
mage/svg+xml;
7 seconds