Note: varnish cache – giải pháp mạnh hơn pagespeed

1. Automated Install for centos 7:

To automatically install dependencies and build the latest mainline version of nginx with the latest stable version of ngx_pagespeed, run:

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

To see other installation options, including options to select the version of nginx or ngx_pagespeed, or install ngx_pagespeed as a dynamic module, run:

bash <(curl -f -L -sS https://ngxpagespeed.com/install) --help
Ref: https://www.modpagespeed.com/doc/build_ngx_pagespeed_from_source

2. Script to install pagespeed module in almalinux 9: 

updated 01.05.2025

a ready-to-run bash script to install and enable PageSpeed module for NGINX on AlmaLinux 9 after you’ve already installed NGINX: 

  • create a script file and save it: nano install_pagespeed_almalinux9.sh
  • make it executable: chmod +x install_pagespeed_almalinux9.sh
  • Run it: sudo ./install_pagespeed_almalinux9.sh
  • check: 
#!/bin/bash
# Install ngx_pagespeed on AlmaLinux 9 with existing NGINX

set -e

NGINX_VERSION=$(nginx -v 2>&1 | awk -F/ '{print $2}')
BUILD_DIR="/usr/local/src"
PAGESPEED_DIR="${BUILD_DIR}/incubator-pagespeed-ngx"
PAGESPEED_CACHE="/var/ngx_pagespeed_cache"
NGINX_BIN="/usr/sbin/nginx"
NGINX_CONF="/etc/nginx/nginx.conf"

echo "📦 Installing dependencies..."
dnf groupinstall "Development Tools" -y
dnf install -y gcc-c++ pcre-devel zlib-devel openssl-devel unzip git wget make

echo "⬇️ Downloading ngx_pagespeed..."
cd "$BUILD_DIR"
rm -rf "$PAGESPEED_DIR"
git clone --recursive https://github.com/apache/incubator-pagespeed-ngx.git
cd incubator-pagespeed-ngx
./scripts/psol_download.py

echo "⬇️ Downloading NGINX source (v$NGINX_VERSION)..."
cd "$BUILD_DIR"
wget "http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz"
tar -xzf "nginx-${NGINX_VERSION}.tar.gz"
cd "nginx-${NGINX_VERSION}"

echo "⚙️ Configuring NGINX with PageSpeed..."
./configure --add-module="$PAGESPEED_DIR" --with-http_ssl_module
make

echo "🧠 Backing up and replacing nginx binary..."
systemctl stop nginx
cp "$NGINX_BIN" "${NGINX_BIN}.bak_$(date +%F_%T)"
cp objs/nginx "$NGINX_BIN"
chmod +x "$NGINX_BIN"

echo "📁 Creating PageSpeed cache directory..."
mkdir -p "$PAGESPEED_CACHE"
chown -R nginx:nginx "$PAGESPEED_CACHE"

echo "📝 Injecting PageSpeed config into nginx.conf..."
if ! grep -q "pagespeed on;" "$NGINX_CONF"; then
  sed -i '/http {/a \
    \    pagespeed on;\
    \    pagespeed FileCachePath '"$PAGESPEED_CACHE"';\
    \    pagespeed EnableFilters combine_javascript,combine_css,collapse_whitespace;\
  ' "$NGINX_CONF"
fi

echo "🔁 Restarting NGINX..."
systemctl start nginx

echo "✅ ngx_pagespeed installed and running on AlmaLinux 9!"

 

Leave a Reply

Your email address will not be published. Required fields are marked *