At work, we are using Varnish, a very good reverse proxy, since many years.
Varnish does a lot of stuff for us. One of the major is the ability to cache responses of our quite slow php backends. Getting a page in 16ms is ever better than 300ms
Since my venue to the London Velocity Conf, I am quite obsessed to test Google ModPagespeed.
The product is not focused on the frontend response time but more on the user experience.
I have done my first test of ModPageSpeed few weeks ago. Results seems very good but one things hurts me. ModPageSpeed proceed in two stage optimization: the first call of the page, ModPageSpeed get the page from PHP and returns the response without any optimization to the client. And in parallel it launches a thread to optimize the page for the next client.
As it don’t optimize the first call, it forces a cache-control “no-cache” on the response.
The problem is that no page will go in the cache of Varnish with a no-cache directive.
One last thing, ModPageSpeed sends different optimizations depending of the User-Agent.
So, one side we have optimized the HTML of the response, increasing user experience, but on the other side we have put more load on our backend.
Thinking about it, I asked myself if we could put ModPageSpeed in front of Varnish. If yes, we could have an optimized HTML and less load on the backend.
The response is yes, we can put ModPageSpeed in front of Varnish !
We just need to install Apache and configure it with “ProxyPass”.
This is all the modules we need:
LoadModule authz_host_module /usr/lib64/httpd/modules/mod_authz_host.so
LoadModule deflate_module /usr/lib64/httpd/modules/mod_deflate.so
LoadModule log_config_module /usr/lib64/httpd/modules/mod_log_config.so
LoadModule setenvif_module /usr/lib64/httpd/modules/mod_setenvif.so
LoadModule proxy_module /usr/lib64/httpd/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib64/httpd/modules/mod_proxy_http.so
LoadModule status_module /usr/lib64/httpd/modules/mod_status.so
LoadModule vhost_alias_module /usr/lib64/httpd/modules/mod_vhost_alias.so
All others modules can be safely disabled.
Since ModPagespeed uses threads, think to start your Apache in worker mode:
If you have more than one vhost, you need to use at least the 18.104.22.168-2191 of ModPagespeed to support multi-vhosts.
A default setup could be:
Allow from all
#Default VHost : ModPagespeed disabled
CustomLog /var/log/httpd/default_access.log combined
#mywebsite.com VHost : ModPagespeed enabled
ModPagespeedMapOriginDomain http://localhost:8000 http://www.mywebsite.com
ModPagespeedMapOriginDomain http://localhost:8000 http://mystaticwebsite.com
ModPagespeedShardDomain mystaticwebsite.com s1.mystaticwebsite.com,s2.mystaticwebsite.com
CustomLog /var/log/httpd/www.mywebsite.com_access.log combined
ProxyPass / http://127.0.0.1:8000/
This configuration is fully operational but not yet tested in production.
Is there someone who has already tested this architecture in production?