Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 14, 2022 06:54 pm GMT

Optimize Your Webserver by Installing a Single NGINX Module

In 2012, Google released version 1.0 of their PageSpeed modules for NGINX and Apache. It has gone largely unnoticed since then. The short of PageSpeed is that if you add it to your web server, you can configure it to optimize anything passing through it using techniques such as minification, format conversion, and even injecting scripts to lazy-load images. You can read more about what it does on the official site.

It sounded great in theory, but how properly install it with NGINX wasn't obvious. While Google does publish scripts to help with the installation, it requires a non-trivial depth of knowledge to do right. After struggling with it for many hours, I wrote a guide for personal future reference.

I recently returned to those notes to entirely automate the process using GitHub Actions. The work is open-source and available on GitHub.

Installation

Run the following as root on a Debian-based machine:

sudo suapt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8028BE1819F3E4A0echo "deb https://nginx-pagespeed.knyz.org/dist/ /" > /etc/apt/sources.list.d/nginx-pagespeed.listecho "Package: *" > /etc/apt/preferences.d/99nginx-pagespeedecho "Pin: origin http://nginx-pagespeed.knyz.org/" >> /etc/apt/preferences.d/99nginx-pagespeedecho "Pin-Priority: 900" >> /etc/apt/preferences.d/99nginx-pagespeedapt updateapt install nginx-full # If NGINX is already installed, an `apt upgrade` works tooecho "pagespeed on;" > /etc/nginx/conf.d/pagespeed.confecho "pagespeed FileCachePath \"/var/cache/pagespeed/\";" >> /etc/nginx/conf.d/pagespeed.confecho "pagespeed FileCacheSizeKb 102400;" >> /etc/nginx/conf.d/pagespeed.confecho "pagespeed FileCacheCleanIntervalMs 3600000;" >> /etc/nginx/conf.d/pagespeed.confecho "pagespeed FileCacheInodeLimit 500000;" >> /etc/nginx/conf.d/pagespeed.confecho "pagespeed RewriteLevel CoreFilters;" >> /etc/nginx/conf.d/pagespeed.confsystemctl reload nginx

The installation process is explained more thoroughly on the GitHub page if you're curious.

Once that is done, you will have an active NGINX + PageSpeed installation that will receive the same updates as upstream NGINX. You can learn more about individual filters that you can enable in the documentation.

This post was originally shared on my Building Better Software Slower blog


Original Link: https://dev.to/knyzorg/optimize-your-webserver-by-installing-a-single-nginx-module-5dga

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To