ngx_pagespeed configuration reference
The minimal nginx directives to get PageSpeed optimization running: enable the module, set a cache path, turn on filters, and choose a rewrite level. This is the quick reference — the full directive list lives in the docs on modpagespeed.com.
A minimal working block
Drop this into an http or server block. It
turns the module on, points it at a writable cache directory, and
enables a conservative set of filters:
pagespeed on; pagespeed FileCachePath /var/cache/ngx_pagespeed; # Optimization level: CoreFilters is the safe, recommended default pagespeed RewriteLevel CoreFilters; # Required handlers for the admin/stats endpoints location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; } location ~ "^/pagespeed_static/" { } location ~ "^/ngx_pagespeed_beacon$" { }
Reload nginx (nginx -t && systemctl reload nginx)
and the worker starts optimizing. Confirm with
curl -sI https://yoursite/ | grep -i x-page-speed.
Enable the module
pagespeed on; activates optimization for the context it
is set in. Set pagespeed off; in a more specific
location to exclude a path — for example an API or admin
area you do not want rewritten.
Cache path
pagespeed FileCachePath sets the on-disk directory where
optimized resources are cached. It must be writable by the nginx
worker user. Put it on fast local storage and keep it off a network
filesystem:
pagespeed FileCachePath /var/cache/ngx_pagespeed;
Rewrite level
pagespeed RewriteLevel selects a preset bundle of
filters. CoreFilters is the recommended default — a
tested, safe set that improves most sites without manual tuning.
PassThrough enables only the filters you turn on by hand.
pagespeed RewriteLevel CoreFilters; # recommended default # pagespeed RewriteLevel PassThrough; # enable filters individually
Enable individual filters
On top of (or instead of) a rewrite level, turn on specific filters
with pagespeed EnableFilters, comma-separated:
pagespeed EnableFilters rewrite_images,collapse_whitespace; pagespeed EnableFilters combine_css,rewrite_javascript;
Use pagespeed DisableFilters to switch off a single
filter from a preset level without dropping the rest.
Full reference
This page covers the directives most installs need to get started. The complete configuration reference — every filter, every directive, and per-engine specifics for 1.1 nginx and 2.0 nginx — lives in the docs on modpagespeed.com.
Full nginx PageSpeed configuration reference