Site icon GetPageSpeed

PageSpeed NGINX Rocky Linux 10: Optimization Guide

PageSpeed NGINX Rocky Linux 10: Optimization Guide

PageSpeed NGINX Rocky Linux 10 automatically optimizes your web pages for faster loading. This module, originally developed by Google, applies optimization techniques like image compression, CSS and JavaScript minification, lazy loading, and cache extension without modifying your application code.

This comprehensive guide shows you how to install and configure the PageSpeed module for NGINX on Rocky Linux 10, AlmaLinux 10, and other Enterprise Linux 10 distributions. You will learn to enable core filters, configure the file cache, and implement advanced optimization strategies. By the end, you will have PageSpeed NGINX Rocky Linux 10 automatically improving your website performance.

Why Use PageSpeed with NGINX

PageSpeed transforms your web server into an automatic optimization engine. Key benefits include:

These optimizations directly improve Core Web Vitals scores without application changes. PageSpeed handles the complexity of web performance optimization automatically.

Prerequisites

Before installing PageSpeed NGINX Rocky Linux 10 packages, ensure you have:

Note: PageSpeed module is available for x86_64 architecture only.

The GetPageSpeed repository provides pre-built PageSpeed packages with all dependencies included.

Installation

Step 1: Configure GetPageSpeed Repository

The GetPageSpeed repository provides enterprise-grade NGINX modules including PageSpeed. Install the repository:

sudo dnf -y install https://extras.getpagespeed.com/release-latest.rpm

Step 2: Install NGINX

If NGINX is not already installed:

sudo dnf -y install nginx
sudo systemctl enable --now nginx

Step 3: Install PageSpeed Module

Install the NGINX PageSpeed module:

sudo dnf -y install nginx-module-pagespeed

After installation, you will see instructions for enabling the module.

Step 4: Create File Cache Directory

PageSpeed requires a writable directory for its file cache:

sudo mkdir -p /var/cache/pagespeed
sudo chown nginx:nginx /var/cache/pagespeed
sudo chmod 755 /var/cache/pagespeed

Step 5: Enable the Module

Add the module loading directive at the top of your NGINX configuration:

# /etc/nginx/nginx.conf
load_module modules/ngx_pagespeed.so;

user nginx;
worker_processes auto;
# ... rest of configuration

Step 6: Basic PageSpeed Configuration

Add PageSpeed directives to your server block:

server {
    listen 80;
    server_name example.com;

    # Enable PageSpeed
    pagespeed on;

    # Specify the file cache directory
    pagespeed FileCachePath /var/cache/pagespeed;

    # Enable CoreFilters (recommended default set)
    pagespeed RewriteLevel CoreFilters;

    # Admin pages for statistics and configuration
    pagespeed Statistics on;
    pagespeed StatisticsLogging on;
    pagespeed LogDir /var/log/pagespeed;

    location / {
        root /usr/share/nginx/html;
        index index.html;
    }

    # PageSpeed admin handler
    pagespeed AdminPath /pagespeed_admin;
    location ~ ^/pagespeed_admin {
        allow 127.0.0.1;
        deny all;
    }
}

Test and reload:

sudo nginx -t && sudo systemctl reload nginx

Understanding PageSpeed Filters

PageSpeed optimization is controlled through filters. Filters are grouped into levels for convenience.

Rewrite Levels

CoreFilters (recommended starting point):

pagespeed RewriteLevel CoreFilters;

Includes safe, widely-applicable optimizations:

OptimizeForBandwidth (conservative):

pagespeed RewriteLevel OptimizeForBandwidth;

Only optimizations that reduce bandwidth without altering page structure.

PassThrough (start from scratch):

pagespeed RewriteLevel PassThrough;

Disables all filters. Enable only specific filters you need.

Enabling Individual Filters

Enable specific filters beyond the rewrite level:

pagespeed EnableFilters lazyload_images,defer_javascript;

Disable specific filters:

pagespeed DisableFilters combine_css,combine_javascript;

Image optimization focus:

pagespeed RewriteLevel CoreFilters;
pagespeed EnableFilters convert_png_to_jpeg,convert_jpeg_to_webp;
pagespeed EnableFilters resize_images,recompress_images;
pagespeed EnableFilters lazyload_images;

JavaScript optimization:

pagespeed RewriteLevel CoreFilters;
pagespeed EnableFilters defer_javascript;
pagespeed EnableFilters prioritize_critical_css;

Mobile optimization:

pagespeed RewriteLevel CoreFilters;
pagespeed EnableFilters lazyload_images;
pagespeed EnableFilters inline_preview_images;
pagespeed EnableFilters resize_mobile_images;

Configuration Examples

Production Configuration

Complete production-ready PageSpeed configuration:

server {
    listen 80;
    server_name example.com;

    # Enable PageSpeed
    pagespeed on;
    pagespeed FileCachePath /var/cache/pagespeed;

    # Use CoreFilters as base
    pagespeed RewriteLevel CoreFilters;

    # Additional image optimizations
    pagespeed EnableFilters lazyload_images;
    pagespeed EnableFilters convert_jpeg_to_webp;
    pagespeed EnableFilters convert_png_to_jpeg;
    pagespeed EnableFilters resize_images;

    # JavaScript optimizations
    pagespeed EnableFilters defer_javascript;

    # CSS optimizations  
    pagespeed EnableFilters prioritize_critical_css;

    # Cache settings
    pagespeed FileCacheSizeKb 1024000;
    pagespeed FileCacheCleanIntervalMs 3600000;
    pagespeed LRUCacheKbPerProcess 8192;
    pagespeed LRUCacheByteLimit 16384;

    # Preserve URL structure for CDN compatibility
    pagespeed PreserveUrlRelativity on;

    location / {
        root /var/www/html;
        index index.html;
    }
}

Excluding Resources

Exclude specific URLs from optimization:

# Exclude admin pages
pagespeed Disallow */admin/*;

# Exclude specific scripts
pagespeed Disallow */tracking.js;

# Exclude by pattern
pagespeed Disallow *.min.js;
pagespeed Disallow *.min.css;

Domain Configuration

Allow PageSpeed to rewrite resources from external domains:

# Map CDN domain
pagespeed MapRewriteDomain cdn.example.com www.example.com;

# Allow rewriting from external domain
pagespeed Domain https://cdn.example.com;

HTTPS Configuration

For HTTPS sites, add these directives:

pagespeed FetchHttps enable;
pagespeed SslCertDirectory /etc/pki/tls/certs;
pagespeed SslCertFile /etc/pki/tls/certs/ca-bundle.crt;

Verification

After configuring PageSpeed NGINX Rocky Linux 10, verify the setup.

Check Response Headers

PageSpeed adds headers to indicate optimization:

curl -sI http://example.com/ | grep -i pagespeed

Expected output:

X-Page-Speed: 1.13.35.2-0

View Statistics

Access the admin console (if enabled):

http://example.com/pagespeed_admin/

This shows:

Check Page Source

View optimized page source to see:

Test with PageSpeed Insights

Use Google PageSpeed Insights to measure improvement:

https://pagespeed.web.dev/

Compare scores before and after enabling PageSpeed.

Cache Management

File Cache Structure

PageSpeed stores optimized resources in the file cache:

/var/cache/pagespeed/
β”œβ”€β”€ http,3example.com/
β”‚   β”œβ”€β”€ ic/  (image cache)
β”‚   β”œβ”€β”€ cf/  (CSS files)
β”‚   β”œβ”€β”€ jf/  (JavaScript files)
β”‚   └── ...

Cache Size Configuration

Control cache size limits:

# Maximum cache size in KB (1GB)
pagespeed FileCacheSizeKb 1048576;

# Cleanup interval in milliseconds (1 hour)
pagespeed FileCacheCleanIntervalMs 3600000;

# Inode limit
pagespeed FileCacheInodeLimit 500000;

Clearing the Cache

Clear PageSpeed cache manually:

sudo rm -rf /var/cache/pagespeed/*
sudo systemctl reload nginx

Or use the admin console cache purge feature.

Troubleshooting

PageSpeed Not Optimizing

Symptom: Pages served without optimization

Solutions:

  1. Verify pagespeed on is in the correct context
  2. Check FileCachePath exists and is writable
  3. Ensure URL is not in Disallow list
  4. Check error log for PageSpeed messages

Broken Page Layout

Symptom: CSS or JavaScript errors after enabling PageSpeed

Solutions:

  1. Disable filters one by one to find the cause
  2. Use pagespeed Disallow for problematic resources
  3. Try OptimizeForBandwidth level first
  4. Check browser console for specific errors

High CPU Usage

Symptom: CPU spikes during optimization

Solutions:

  1. Increase LRUCacheKbPerProcess for better caching
  2. Reduce image optimization aggressiveness
  3. Pre-warm cache during low traffic periods
  4. Exclude large files from optimization

Cache Permission Errors

Symptom: β€œFailed to create cache directory” errors

Solutions:

sudo chown -R nginx:nginx /var/cache/pagespeed
sudo chmod -R 755 /var/cache/pagespeed
sudo restorecon -Rv /var/cache/pagespeed  # For SELinux

SELinux Configuration

For SELinux systems, set the correct context:

sudo semanage fcontext -a -t httpd_cache_t "/var/cache/pagespeed(/.*)?"
sudo restorecon -Rv /var/cache/pagespeed

If PageSpeed needs to fetch external resources:

sudo setsebool -P httpd_can_network_connect 1

Performance Tuning

Memory Settings

Optimize memory usage for high-traffic sites:

# Per-process LRU cache
pagespeed LRUCacheKbPerProcess 8192;
pagespeed LRUCacheByteLimit 16384;

# Shared memory cache
pagespeed CreateSharedMemoryMetadataCache /var/cache/pagespeed/metadata 51200;

Thread Settings

Configure optimization threads:

pagespeed NumRewriteThreads 4;
pagespeed NumExpensiveRewriteThreads 4;

Beacon Configuration

Enable beacon for real user monitoring:

pagespeed EnableFilters add_instrumentation;
pagespeed BeaconUrl /pagespeed_beacon;

Complete Production Configuration

Here is a complete PageSpeed NGINX Rocky Linux 10 configuration:

# /etc/nginx/nginx.conf
load_module modules/ngx_pagespeed.so;

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

events {
    worker_connections 1024;
}

http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    sendfile on;
    keepalive_timeout 65;

    server {
        listen 80;
        server_name example.com;

        # Enable PageSpeed
        pagespeed on;
        pagespeed FileCachePath /var/cache/pagespeed;

        # Optimization level
        pagespeed RewriteLevel CoreFilters;
        pagespeed EnableFilters lazyload_images,defer_javascript;
        pagespeed EnableFilters convert_jpeg_to_webp,resize_images;
        pagespeed EnableFilters prioritize_critical_css;

        # Cache configuration
        pagespeed FileCacheSizeKb 1048576;
        pagespeed LRUCacheKbPerProcess 8192;

        # Exclude admin areas
        pagespeed Disallow */admin/*;
        pagespeed Disallow */wp-admin/*;

        location / {
            root /usr/share/nginx/html;
            index index.html;
        }

        # PageSpeed admin (restrict access)
        pagespeed AdminPath /pagespeed_admin;
        location ~ ^/pagespeed_admin {
            allow 127.0.0.1;
            deny all;
        }
    }
}

Test and apply:

sudo nginx -t && sudo systemctl reload nginx

For more NGINX performance guides:

Conclusion

PageSpeed NGINX Rocky Linux 10 provides automatic web optimization without application changes. The module handles image compression, code minification, lazy loading, and dozens of other optimizations that directly improve Core Web Vitals scores.

Start with CoreFilters for safe, comprehensive optimization. Add specific filters based on your site’s needs. Monitor the admin console to track optimization effectiveness and adjust settings accordingly.

For production deployments, ensure adequate disk space for the file cache and configure appropriate memory limits. The PageSpeed module can significantly improve page load times and user experience with minimal configuration effort.

D

Danila Vershinin

Founder & Lead Engineer

NGINX configuration and optimizationLinux system administrationWeb performance engineering

10+ years NGINX experience β€’ Maintainer of GetPageSpeed RPM repository β€’ Contributor to open-source NGINX modules

Exit mobile version