Even though my personal blog is, well, a personal project, I’ve always tried to run it with some level of professionalism. One aspect of it is about keeping up with the technology, such as optimising website and content to deliver faster and better experience to the blog reader. My latest project is to use Google PageSpeed on my website.
Google PageSpeed’s purpose is to speed up a website and reduce page load time. It automatically optimises website contents, and includes many configurable optimisation filters. The magic with it is that you don’t need to change your existing content or workflow.
I’m not new to Google PageSpeed. I had previously used it when my website was hosted on DreamHost’s shared hosting plan. One of DreamHost’s nice value-added service was PageSpeed integration. I turned it on. It was a simple on-off toggle in their control panel, and it makes magic happen.
However, after moving my blog website to a DreamCompute virtual server instance, the PageSpeed integration was gone. It was up to me to put PageSpeed in myself. It wasn’t a high priority at the start. I did have an invite to sign up with Google’s PageSpeed Service, a service they have just last week announced is deprecated.
So now I’ve gotten around to putting in Google PageSpeed myself, and stumbled on some problems. I thought I’d share a little about the install experience.
To use Google PageSpeed, you need to run your website with either Apache or Nginx. The actual installation instructions are relatively straightforward. You can simply refer to Google’s PageSpeed Module webpage for instructions. There are prebuilt packages Apache on CentOS/Fedora and Debian/Ubuntu, both 32-bit and 64-bit platforms. This is probably the easiest way to get PageSpeed installed.
Once that’s done, there are a few things you need to take note. First, PageSpeed does not work on HTTPS resources. Yup. How strange isn’t it? If you run your website on HTTPS, like I do, you need to add the following line to /etc/httpd/conf.d/pagespeed.conf
:
ModPagespeedFetchHttps enable
This is documented, but it just doesn’t seem terribly obvious when you’re new to PageSpeed.
The next thing to know is about PageSpeed admin pages. You may have read that they are accessed, by default, at the path /pagespeed_admin and /pagespeed_global_admin. Well, unfortunately, your WordPress configuration may screw up the delivery of PageSpeed admin pages because of the former’s fancy mod_rewrite rules in .httaccess. Do you see errors like the below in your Apache error log?
AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use ‘LimitInternalRecursion’ to increase the limit if necessary. Use ‘LogLevel debug’ to get a backtrace.
The simplest solution seems to be to create a new virtual server specifically for serving the PageSpeed admin pages. So here’s my suggestion. Create a new psadmin.conf (or whatever other name you fancy, as long as it ends in .conf) file in the /etc/httpd/conf.d directory. Put the contents below into the file:
Listen 8080 <VirtualHost 127.0.0.1:8080> DocumentRoot "/home/someuser/pagespeed" <Location /pagespeed_admin> Order allow,deny Allow from localhost Allow from 127.0.0.1 SetHandler pagespeed_admin </Location> <Location /pagespeed_global_admin> Order allow,deny Allow from localhost Allow from 127.0.0.1 SetHandler pagespeed_global_admin </Location> </VirtualHost> <Directory "/home/someuser/pagespeed"> Options Indexes FollowSymLinks AllowOverride None # Allow open access: Require all granted </Directory>
I’ve created a new DocumentRoot in another location (/home/someuser/pagespeed), which is empty, in case your original DocumentRoot has got some contents that you don’t want to show up or interfere with the PageSpeed admin virtualhost. The new VirtualHost runs on port 8008 and listens only on localhost (127.0.0.1). To access this page, your web browser only needs to go to http://127.0.0.1:8080/.
Alright, in practice, that’s not so simple, because your web server is in some remote location, and your web browser is in your own local PC. Accessing the “localhost” of the remote server will take some really simple port-forwarding magic with SSH. Just connect to your remote server with the following SSH command:
ssh -L 8080:127.0.0.1:8080 user@server.com
Just replace user@server.com with whatever is appropriate for you.
Go to the PageSpeed admin, and click around to see a bunch of stuffs, like statistics and error messages.
Now, your WordPress website should fly much better with Google PageSpeed.
1 thought on “Using PageSpeed with WordPress and SSL”
View Comment Policy