Mapping origin domains
Authorizing and Mapping Urls and Domains
In order to improve the performance of web pages, PageSpeed must examine and modify the content of resources referenced on those pages. To do that, it must fetch those resources using HTTP, using the URL reference specified on the HTML page.
In some cases, the URL specified in the HTML file is not the best URL to use to fetch the resource. Scenarios where this is a concern include:
- If the server is behind a load balancer, and it's more efficient to reference the server directly by its IP address, or as 'localhost'.
- The server has a special DNS configuration
- The server is behind a firewall preventing outbound connections
- The server is running in a CDN or proxy, and must go back to the origin server for the resources
- The server needs to service https requests
In these situations the remedy is to map the origin domain:
pagespeed MapOriginDomain origin_to_fetch_from origin_specified_in_html [host_header]
Note: The optional [host_header] argument is a new feature as of PageSpeed 184.108.40.206.
Wildcards can also be used in the
pagespeed MapOriginDomain localhost *.example.com
origin_to_fetch_from can include a path after the domain name, e.g.
pagespeed MapOriginDomain localhost/example *.example.com
When a path is specified, the source domain is mapped to the destination domain and the source path is mapped to the concatenation of the path from
origin_to_fetch_from and the source path. For example, given the above mapping,
http://www.example.com/index.html will be mapped to
origin_specified_in_html can specify https but the
origin_to_fetch_from can only specify http, e.g.
pagespeed MapOriginDomain http://localhost https://www.example.com
This directive lets the server accept https requests for
www.example.com without requiring a SSL certificate to fetch resources. For example, given the above mapping, and assuming the server is configured for https support, PageSpeed will fetch and optimize resources accessed using
https://www.example.com, fetching the resources from
http://localhost, which can be the same server process or a different server process.
pagespeed MapOriginDomain http://localhost https://www.example.com pagespeed ShardDomain https://www.example.com https://example1.cdn.com, https://example2.cdn.com
In this example the https origin domain is mapped to
localhost and sharding is used to parallelize downloads across hostnames. Note that the shards also specify https.
By specifying a source domain in this directive, you are authorizing PageSpeed to rewrite resources found in that domain. For example, in the above directives, 'www.example.com' gets authorized for rewrites from HTML files, but 'localhost' does not. See
When PageSpeed fetches resources from a mapped origin domain, it specifies the source domain in the
Host: header in the request. You can override the
Host: header value with the optional third parameter
host_header. See Mapping Origins with a Shared Domain for an example.
LoadFromFile to load origin resource directly from the filesystem and avoid an HTTP connection altogether.
These directives can be used in location-specific configuration sections.