PageSpeed with HTTPS, Apache and Tomcat
Feb 21, 2016
PageSpeed is a tool by Google which rewrites/optimizes resources served by your web server so that your site loads faster. I think it was designed to work with sites that largely serve static content. Most PHP based sites are like that. For example, Wordpress installations can directly reside in the DocumentRoot of Apache. That makes it straightforward to configure PageSpeed. But if you are using a Java web application fronted by Apache, the PageSpeed documentation doesn't help you much.
PageSpeed configuration for dynamic content
If your web application serves content using a URL which does not map to a physical location in your
DocumentRoot, PageSpeed will not be able to find it. For example, this blog runs on Apache Roller which serves static files using a logical path and not a physical path. If relative to your web application's root, the CSS files are present in this phsyical location:
And the CSS files are served with this logical URL:
PageSpeed will try to look for this physical location relative to
To map the physical location to the logical location, we need to use the ModPagespeedLoadFromFile directive in your pagespeed.conf (For Debian based systems, the file should be at
ModPagespeedLoadFromFile "https://satishchilukuri.com/blog/resource" \ "/opt/tomcat-base/webapps/ROOT/themes/alaru/"
Even after doing that, PageSpeed wasn't working for me. All requests to resources cached by PageSpeed resulted in errors like this:
[Sat Feb 20 16:25:03.177771 2016] [authz_core:error] [pid 10833:tid 139886422066944] [client 220.127.116.11:56396] AH01630: client denied by server configuration: uri /blog/resource/highlightjs,_highlight.8.4.mi n.js+js,_alaru.js.pagespeed.jc.8gGwxNuCGf.js, referer: https://satishchilukuri.com/blog/
To fix such errors you need to allow access to the logical location in the URL. This needs to be done in your Apache's virtual host configuration, via the Location directive:
<Location /blog/resource> Require all granted Options -Indexes </Location>
PageSpeed configuration for HTTPS
If you look at the PageSpeed documentation for HTTPS support, it says that version 1.10 supports HTTPS by default. However the documentation doesn't say that version 1.10 is the beta version of PageSpeed. So if you have not installed the beta version, note that you won't get version 1.10 even if you do a
apt-get update && apt-get upgrade
Since I'm using Tomcat to fetch resources, I didn't have to use
ModPagespeedMapOriginDomain to map https domain to http.
ModPagespeedLoadFromFile is needed, which we already did above.
If you are using LetsEncrypt like this site does, then the certificates will not be present in the default location that PageSpeed looks for. So edit your pagespeed.conf and give the correct path for
ModPagespeedSslCertDirectory and give the location to the cert.pem file:
ModPagespeedSslCertDirectory /etc/letsencrypt/live/satishchilukuri.com/ ModPagespeedSslCertFile /etc/letsencrypt/live/satishchilukuri.com/cert.pem