paint-brush
Optimize Your Webserver by Installing a Single NGINX Module by@knyzorg
209 reads

Optimize Your Webserver by Installing a Single NGINX Module

by Slava Knyazev
Slava Knyazev HackerNoon profile picture

Slava Knyazev

@knyzorg

Sometimes I have good ideas. Writing about Building Better Software...

January 17th, 2022
Read on Terminal Reader
Read this story in a terminal
Print this story
Read this story w/o Javascript
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Google released version 1.0 of their [PageSpeed modules for NGINX and Apache in 2012. PageSpeed can optimize anything passing through it using techniques such as minification, format conversion, and even injecting scripts to lazy-load images. The work is open-source and available on [GitHub] using GitHub Actions. The installation process is explained more thoroughly on the GitHub page if you're curious. You can learn more about individual filters that you can enable in the [documentation]

Companies Mentioned

Mention Thumbnail
Apache
Mention Thumbnail
Google
featured image - Optimize Your Webserver by Installing a Single NGINX Module
1x
Read by Dr. One voice-avatar

Listen to this story

Slava Knyazev HackerNoon profile picture
Slava Knyazev

Slava Knyazev

@knyzorg

Sometimes I have good ideas. Writing about Building Better Software Slower at https://bbss.dev

About @knyzorg
LEARN MORE ABOUT @KNYZORG'S
EXPERTISE AND PLACE ON THE INTERNET.


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 su
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8028BE1819F3E4A0
echo "deb https://nginx-pagespeed.knyz.org/dist/ /" > /etc/apt/sources.list.d/nginx-pagespeed.list
echo "Package: *" > /etc/apt/preferences.d/99nginx-pagespeed
echo "Pin: origin http://nginx-pagespeed.knyz.org/" >> /etc/apt/preferences.d/99nginx-pagespeed
echo "Pin-Priority: 900" >> /etc/apt/preferences.d/99nginx-pagespeed
apt update
apt install nginx-full # If NGINX is already installed, an `apt upgrade` works too
echo "pagespeed on;" > /etc/nginx/conf.d/pagespeed.conf
echo "pagespeed FileCachePath \"/var/cache/pagespeed/\";" >> /etc/nginx/conf.d/pagespeed.conf
echo "pagespeed FileCacheSizeKb 102400;" >> /etc/nginx/conf.d/pagespeed.conf
echo "pagespeed FileCacheCleanIntervalMs 3600000;" >> /etc/nginx/conf.d/pagespeed.conf
echo "pagespeed FileCacheInodeLimit 500000;" >> /etc/nginx/conf.d/pagespeed.conf
echo "pagespeed RewriteLevel CoreFilters;" >> /etc/nginx/conf.d/pagespeed.conf
systemctl 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.


Also Published Here

L O A D I N G
. . . comments & more!

About Author

Slava Knyazev HackerNoon profile picture
Slava Knyazev@knyzorg
Sometimes I have good ideas. Writing about Building Better Software Slower at https://bbss.dev

TOPICS

THIS ARTICLE WAS FEATURED IN...

Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Hashnode
Learnrepo

Mentioned in this story

companies
X REMOVE AD