Configuration
Configure mod_pagespeed 1.1 for nginx, Apache, IIS, and Envoy. Module states, configuration directives, virtual hosts, and reverse proxy setup.
This reference covers the configuration options available in mod_pagespeed 1.1 across all supported platforms: nginx, Apache, IIS, and Envoy.
Enabling the module
Load the module and enable it in your server block:
load_module modules/ngx_pagespeed.so;
http {
server {
pagespeed on;
# Required location blocks
location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" {
add_header "" "";
}
location ~ "^/pagespeed_static/" { }
location ~ "^/ngx_pagespeed_beacon$" { }
}
}
The distribution package loads the module automatically on install. Enable it in pagespeed.conf or your virtual host configuration:
ModPagespeed on
The installer registers the module in IIS automatically. Configure it through pagespeed.config, a flat-text configuration file with one directive per line.
The module looks for configuration files in this order:
- Site-level:
pagespeed.configin the website root directory - Server-level:
%ProgramData%\We-Amp\IISWebSpeed\pagespeed.config
Site-level settings override server-level settings. If pagespeed.config is not found, the module falls back to iiswebspeed.config (legacy filename).
Enable optimization by adding to your pagespeed.config:
pagespeed on
Envoy
mod_pagespeed 1.1 is available as an HTTP filter for Envoy. This integration is in beta. Contact us for configuration guidance.
Module states
mod_pagespeed 1.1 supports three operational states:
| State | Behavior |
|---|---|
on | Full optimization. The module rewrites HTML and serves optimized resources. |
standby | Serves previously optimized .pagespeed. resources and responds to query-parameter requests, but does not optimize new traffic. Use this to drain optimized resources before fully disabling the module. |
unplugged | Fully disabled. The module does not intercept any requests. This state can only be set at the top level or within a virtual host block, not in directory-level configuration. |
pagespeed standby;
ModPagespeed standby
pagespeed standby
Configuration directives
The table below lists key directives with their defaults.
In nginx, prefix each directive with pagespeed and terminate with a semicolon.
pagespeed HonorCsp on;
pagespeed RespectVary on;
pagespeed DisableRewriteOnNoTransform on;
pagespeed LowercaseHtmlNames off;
pagespeed ModifyCachingHeaders on;
pagespeed XHeaderValue "Powered by mod_pagespeed";
pagespeed PreserveUrlRelativity off;
pagespeed StaticAssetPrefix "/pagespeed_static/";
pagespeed AddResourceHeader "X-Custom" "value";
pagespeed ListOutstandingUrlsOnError off;
In Apache, prefix each directive with ModPagespeed.
ModPagespeedHonorCsp on
ModPagespeedRespectVary on
ModPagespeedDisableRewriteOnNoTransform on
ModPagespeedLowercaseHtmlNames off
ModPagespeedModifyCachingHeaders on
ModPagespeedXHeaderValue "Powered by mod_pagespeed"
ModPagespeedPreserveUrlRelativity off
ModPagespeedStaticAssetPrefix "/pagespeed_static/"
ModPagespeedAddResourceHeader "X-Custom" "value"
ModPagespeedListOutstandingUrlsOnError off
In IIS, use pagespeed.config with one directive per line. Prefix each directive with pagespeed.
pagespeed HonorCsp on
pagespeed RespectVary on
pagespeed DisableRewriteOnNoTransform on
pagespeed LowercaseHtmlNames off
pagespeed ModifyCachingHeaders on
pagespeed XHeaderValue "Powered by mod_pagespeed"
pagespeed PreserveUrlRelativity off
pagespeed StaticAssetPrefix "/pagespeed_static/"
pagespeed AddResourceHeader "X-Custom" "value"
pagespeed ListOutstandingUrlsOnError off
The pagespeed.config format also accepts ModPagespeed and iispeed as directive prefixes for compatibility. The pagespeed prefix is recommended.
| Directive | Default | Description |
|---|---|---|
HonorCsp | off | When enabled, mod_pagespeed respects Content-Security-Policy headers and avoids injecting resources that would violate the policy. |
RespectVary | off | When enabled, mod_pagespeed respects Vary headers on resources. Resources with Vary headers that indicate per-request variation are not rewritten. |
DisableRewriteOnNoTransform | on | When enabled, mod_pagespeed does not optimize resources served with Cache-Control: no-transform. |
LowercaseHtmlNames | off | When enabled, mod_pagespeed lowercases all HTML tag and attribute names during parsing. |
ModifyCachingHeaders | on | Controls whether mod_pagespeed sets caching headers on HTML responses. Do not disable this unless you fully understand the interaction with downstream caches. Disabling it can cause stale optimized content to be served. |
XHeaderValue | (version string) | Sets the value of the X-Mod-Pagespeed (Apache) or X-Page-Speed (nginx/IIS) response header. |
PreserveUrlRelativity | off | When enabled, mod_pagespeed preserves the relativity of URLs in rewritten HTML. Relative URLs remain relative rather than being converted to absolute URLs. |
StaticAssetPrefix | /pagespeed_static/ | Sets the URL prefix for mod_pagespeed’s static assets (JavaScript libraries, images used by filters). |
AddResourceHeader | (none) | Adds a custom HTTP header to all optimized resources. This directive is repeatable: specify it multiple times to add multiple headers. |
ListOutstandingUrlsOnError | off | When enabled, mod_pagespeed includes a list of outstanding resource fetch URLs in error responses. Enable this only for debugging; do not use in production. |
Location-specific configuration
mod_pagespeed directives can be scoped to specific parts of your site. The available scoping mechanisms vary by platform.
Apache supports configuration at several levels:
pagespeed.conf— Global defaults that apply to all virtual hosts.<VirtualHost>— Per-site overrides.<Directory>and<Location>— Target specific filesystem paths or URL paths..htaccess— Per-directory configuration placed in the document root or subdirectories.
.htaccess configuration is re-read on every request, which adds per-request overhead. For high-traffic sites, prefer <Directory> or <Location> blocks in the server configuration.
Example using <Location>:
<Location /images/>
ModPagespeedDisableFilters convert_jpeg_to_webp
</Location>
In nginx, use server and location blocks to scope directives:
server {
pagespeed on;
location /static/ {
pagespeed off;
}
}
Directives set in a server block apply to all locations within that server unless overridden by a more specific location block.
IIS supports configuration at two levels:
- Server-level:
%ProgramData%\We-Amp\IISWebSpeed\pagespeed.config— applies to all websites on the server. - Site-level:
pagespeed.configin the website root directory — overrides server-level settings for that site.
Within a configuration file, use match rules to scope directives to specific URLs or hostnames:
# Only optimize requests matching this host
hostname: ^www\.example\.com$
pagespeed on
pagespeed EnableFilters rewrite_images
# Match a specific URL path
path: ^/blog/
pagespeed EnableFilters prioritize_critical_css
Match rules use RE2 regular expressions. The hostname and path keys match against the request hostname and URL path respectively.
Virtual hosts
Each virtual host can carry its own mod_pagespeed configuration. Directives set at the global level serve as defaults; virtual host configuration overrides them.
One requirement: HTML pages and the optimized resources they reference must share the same configuration options. If a virtual host serves HTML that references resources optimized under a different set of options, the resources may not be found or may be re-optimized unnecessarily.
server {
server_name site-a.example.com;
pagespeed on;
pagespeed EnableFilters rewrite_images;
}
server {
server_name site-b.example.com;
pagespeed on;
pagespeed EnableFilters collapse_whitespace;
}
<VirtualHost *:80>
ServerName site-a.example.com
ModPagespeed on
ModPagespeedEnableFilters rewrite_images
</VirtualHost>
<VirtualHost *:80>
ServerName site-b.example.com
ModPagespeed on
ModPagespeedEnableFilters collapse_whitespace
</VirtualHost>
Place a pagespeed.config file in each website’s root directory. Each file can carry its own set of directives:
Site A (C:\inetpub\site-a\pagespeed.config):
pagespeed on
pagespeed EnableFilters rewrite_images
Site B (C:\inetpub\site-b\pagespeed.config):
pagespeed on
pagespeed EnableFilters collapse_whitespace
Alternatively, use match rules in the server-level config to scope directives by hostname:
hostname: ^site-a\.example\.com$
pagespeed EnableFilters rewrite_images
hostname: ^site-b\.example\.com$
pagespeed EnableFilters collapse_whitespace
Reverse proxy configuration
When mod_pagespeed runs behind a reverse proxy (such as nginx, Varnish, or a CDN), keep the following in mind:
- The proxy must forward the original
Hostheader to the backend so that mod_pagespeed generates correct URLs for optimized resources. - If the proxy terminates TLS, configure mod_pagespeed to recognize the
X-Forwarded-Protoheader so that it generateshttps://URLs for optimized resources. - Ensure that
.pagespeed.resource URLs are routed to the backend running mod_pagespeed. The proxy must not cache these resources independently unless you configure cache lifetimes carefully. - If the proxy strips or modifies response headers, verify that mod_pagespeed’s
X-Mod-PagespeedorX-Page-Speedheader andCache-Controldirectives pass through intact.