I've moved my ngx_pagespeed testing from local virtualbox CentOS 6.4 instance, to my live site for testing. But have encountered an interesting issue with haproxy load balanced setup and CDN usage and was wondering how and what ngx_pagespeed settings and options can be used to work around this.
Background of live site/server setup:
* haproxy 1.5.x front end on port 80 load balancer
* 4x 512MB memory based VPS each running nginx 1.4.0 backend on port 8888
* 1 of the VPS with ngx_pagespeed 1.5.27.2 beta for testing first before deploying to the other 3x VPSes
* All run CentOS 6.4 32bit
VPS ip addresses and haproxy sets a cookie to ensure persistance on same backend
* vps1 ip address = 1.2.3.4 no ngx_pagespeed installed yet (cookie name vps1)
* vps2 ip address = 1.2.3.5 no ngx_pagespeed installed yet (cookie name vps2)
* vps3 ip address = 1.2.3.6 no ngx_pagespeed installed yet (cookie name vps3)
* vps4 ip address = 1.2.3.7 only this VPS with ngx_pagespeed installed (cookie name vps4)
So have following settings in ngx
pagespeed EnableFilters rewrite_domains;
** The Problem **
Now this is all fine so far... well that's what I thought until I started testing
mydomain.com on various page speed test sites such as
loads.in,
webpagetest.org and
gtmetrix.com. Sometimes, these tests report bad requests where the ngx_pagespeed rewritten CSS/JS url link gives 404/410 errors.
When I check the waterfall output and look at response header for the haproxy set cookie on these bad request tests, I notice that
mydomain.com html has cookie name vps4 suggesting it was served from vps4 on 1.2.3.7. But the bad requested CSS or JS file has response header cookie set to vps1 or vps2 or vps3 for the non ngx_pagespeed based Nginx backend servers.
I guess this is because the MapRewriteDomain is placing
cdn.mydomain.com into html and that cdn.mydomain CNAME is set to
mydomain.com origin on port 80 via
cdn77.com CDN service which hits haproxy first and haproxy is directing the request to a VPS that doesn't have ngx_pagespeed enabled. So what should I be doing ngx_pagespeed settings wise ?
If I install ngx_pagespeed on vps1, vps2 and vps3 as well, won't the rewritten CSS/JS url links differ between each VPS as well ? So hitting
cdn.mydomain.com CSS/JS links won't necessarily call the right VPS ?
** Possible solution ??? **
Would I need to map the origin domain to each VPS's specific ipaddress instead for each VPS ?
i.e. for vps4 set pagespeed option
vps4 1.2.3.7 server's Nginx vhost would contain
server {
listen 8888;
Would that work ?