Incorrect CSS URL sharding

52 views
Skip to first unread message

Aniruddha Rajarshi

unread,
Jul 1, 2016, 4:53:12 PM7/1/16
to mod-pagespeed-discuss
Hi,
I believe that pagespeed has a bug somewhere in it's sharding/css rewriting code.


Configuration overview

I have an apache server configured as a reverse proxy with pagespeed installed on it.  Traffic is proxied to a backend server and resources are sharded to a CDN.  The backend has one html file that references a css file which has one background image among other things. (I am attaching the html file and css file and pasting the apache configuration below).



Problem details

The proxy/pagespeed server is configured to shard resources to a cdn.  The background image is being sharded incorrectly.


My shard is: http://shard1.lagrange.ninja/abckey


The css file is correctly sharded to http://shard1.lagrange.ninja/abckey/A.style2.css.pagespeed.cf._2C-rw2qWw.css


However the background url within the optimized css file is not sharded to http://shard1.lagrange.ninja/abckey


The error in the optimized css is:


body  {

    background-image: url("/xabsolute_web_page_background1.jpg.pagespeed.ic.t9nWGaBPUk.jpg");

}


This resource will be incorrectly fetched from http://shard1.lagrange.ninja/xabsolute_web_page_background1.jpg.pagespeed.ic.t9nWGaBPUk.jpg


The correct location is:  http://shard1.lagrange.ninja/abckey/xabsolute_web_page_background1.jpg.pagespeed.ic.t9nWGaBPUk.jpg


The correct css would be:


body  {

    background-image: url("http://shard1.lagrange.ninja/abckey/xabsolute_web_page_background1.jpg.pagespeed.ic.t9nWGaBPUk.jpg");

}


The url of the reverse proxy where you can recreate the error is http://ani-test-backend.lagrange.ninja/welcome.html


NOTE:  the background url in the css file is an absolute url.  I have noticed that the problem does not recreate when using a relative url.




The apache vhost configuration on the reverse proxy


<VirtualHost *:80>

  ServerName ani-test-backend.lagrange.ninja


  <IfModule pagespeed_module>

  ModPagespeed On


  AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript text/javascript text/x-js text/x-javascript


  ModPagespeedEnableFilters add_instrumentation

  ModPagespeedDomain ani-test-backend.lagrange.ninja


  ErrorLog ${APACHE_LOG_DIR}/error.log

  CustomLog ${APACHE_LOG_DIR}/access.log combined


  ModPagespeedMapOriginDomain balancer://cluster_0_0/ ani-test-backend.lagrange.ninja/


  # CDN Sharding is enabled.

   ModPagespeedShardDomain http://ani-test-backend.lagrange.ninja http://shard1.lagrange.ninja/abckey


  </IfModule>



  ProxyPreserveHost On


 ####### balancers ########


  <Proxy balancer://cluster_0_0>


   BalancerMember http://130.211.199.75:80 route=0 timeout=600 retry=0 connectiontimeout=60 loadfactor=1

   ProxySet lbmethod=bybusyness

  </Proxy>


  ######### paths ##########



  # ProxyPass configuration for path '/'.

  ProxyPass /abckey/ balancer://cluster_0_0/

  ProxyPass / balancer://cluster_0_0/

  #ProxyPassReverse / balancer://cluster_0_0/

  RequestHeader set X-Forwarded-Proto http


</VirtualHost>




I have been debugging this problem for several days now and appreciate any help that you can provide.

Thanks!

Otto van der Schaaf

unread,
Jul 3, 2016, 5:49:06 AM7/3/16
to mod-pagespeed-discuss
I tried to reproduce your problem on my machine using a simplified setup but couldn't. 

I'm wondering which exact url and host header are hitting the pagespeed-enabled proxy when http://shard1.lagrange.ninja/abckey/A.style2.css.pagespeed.cf.nMHRVU1XX5.css is requested?

Otto

--
You received this message because you are subscribed to the Google Groups "mod-pagespeed-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mod-pagespeed-di...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mod-pagespeed-discuss/66372e96-f47e-4e8a-b644-3ea4feed342e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Message has been deleted

Aniruddha Rajarshi

unread,
Jul 5, 2016, 12:28:29 PM7/5/16
to mod-pagespeed-discuss
Hi,

The url that is hitting the pagespeed-enabled proxy from CDN is 

GET /abckey/A.style2.css.pagespeed.cf._2C-rw2qWw.css HTTP/1.1" 200 ec7deca8-42c6-11e6-94ce-c940a41b48b4 398 20421 P "Amazon CloudFront" "ani-test-backend.lagrange.ninja" 54.240.149.15 - .

Whereas,  for the image : 

1. For image with absolute path  : CDN is requesting the resource without the key as :

GET /xabsolute_web_page_background.jpg.pagespeed.ic.t9nWGaBPUk.jpg HTTP/1.1" 200 65b71e82-42cc-11e6-94ce-c940a41b48b4 411 34484 P "Amazon CloudFront" "ani-test-backend.lagrange.ninja" 54.240.149.15 -


2.For images with relative path: CDN is requesting the resource with the key as :

GET /abckey/xweb_page_background.jpg.pagespeed.ic.t9nWGaBPUk.jpg HTTP/1.1" 200 65b71e82-42cc-11e6-94ce-c940a41b48b4 411 34484 P "Amazon CloudFront" "ani-test-backend.lagrange.ninja" 54.240.149.15 -

Thanks!
Aniruddha


Note : CSS file should be big enough so that pagespeed won't put the content of css file as an in-line element in html file. 
To unsubscribe from this group and stop receiving emails from it, send an email to mod-pagespeed-discuss+unsub...@googlegroups.com.

Otto van der Schaaf

unread,
Jul 5, 2016, 1:10:42 PM7/5/16
to mod-pagespeed-discuss

On Tue, Jul 5, 2016 at 6:28 PM, Aniruddha Rajarshi <anir...@webscalenetworks.com> wrote:

The url that is hitting the pagespeed-enabled proxy from CDN is 

GET /abckey/A.style2.css.pagespeed.cf._2C-rw2qWw.css HTTP/1.1" 200 ec7deca8-42c6-11e6-94ce-c940a41b48b4 398 20421 P "Amazon CloudFront" "ani-test-backend.lagrange.ninja" 54.240.149.15 - .


So it looks like the CDN changes the hostname before it forwards it to your proxy here, correct? 
The incoming CDN request here would be for "shard1.lagrange.ninja", and the CDN will request with host "ani-test-backend.lagrange.ninja" from your proxy?

That might confuse PageSpeed, because "ani-test-backend.lagrange.ninja" is not in the list of configured shards. I think PageSpeed expects requests for "shard1.lagrange.ninja", which represents (your only) actual shard.

Otto

Aniruddha Rajarshi

unread,
Jul 5, 2016, 3:35:42 PM7/5/16
to mod-pagespeed-discuss
Hi,

yes, CDN changes the hostname before it forwards the request to the proxy and  the incoming request to CDN would be for "shard1.lagrange.ninja", and the CDN will request with host "ani-test-backend.lagrange.ninja" from the proxy.

However, when pagespeed rewrites the url into css file, at that time the error is occurring (CDN is not involved at this point). That is, when pagespeed rewrites the absolute url, it rewrites it incorrectly into the css file (without the key) like :


Whereas, pagespeed correctly writes the relative URL (with the key) like :


So, I think it might not be the problem with the configuration and it may has something related to how pagespeed deals with the absolute and relative urls.

Jeff Kaufman

unread,
Jul 6, 2016, 9:58:23 AM7/6/16
to mod-pagespeed-discuss
Trying to repro this now.

On Tue, Jul 5, 2016 at 3:35 PM, Aniruddha Rajarshi
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mod-pagespeed-di...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mod-pagespeed-discuss/01e4b9cd-a50a-4547-8030-ff4bed9b9f20%40googlegroups.com.

Jeff Kaufman

unread,
Jul 6, 2016, 12:47:24 PM7/6/16
to mod-pagespeed-discuss
I didn't successfully repor this, but I did discover a different bug,
in ngx_pagespeed:
https://github.com/pagespeed/mod_pagespeed/issues/1339

Aniruddha Rajarshi

unread,
Jul 12, 2016, 11:44:43 AM7/12/16
to mod-pagespeed-discuss
Hi,

I have simplified the stuff to reproduce the bug. 

This is my vhost configuration on apache : 

    ModPagespeed On
    ModPagespeedDomain ani-test-noproxy1.lagrange.ninja


I have one html file which references to an external css file. The external css is large enough so that pagespeed won't convert css content as an inline html element. The css file contains one image :

body  {
    background-image: url("../../absolute_web_page_background2.jpg");
}

The image is already at the root. But I have intentionally added ../.. at the front. Ideally it should not matter and the sharded image url must be http://shardone.lagrange.ninja/mykey/absolute.pagespeed.webp.

However, the sharded image url from the pagespeed is  http://shardone.lagrange.ninja/absolute.pagespeed.webp. This url does not contain the "mykey" path of the url and hence I am getting 404 error.

According to the configuration, pagespeed should consider http://shardone.lagrange.ninja/mykey as the root but it seems like it doesn't do so. It considers this  "http://shardone.lagrange.ninja" as the root. 

Note : For the CDN I am using amazon cloudfront where my origin domain is ani-test-noproxy1.lagrange.ninja and CNAME is shardone.lagrange.ninja. 

Aniruddha Rajarshi

unread,
Jul 18, 2016, 4:06:54 PM7/18/16
to mod-pagespeed-discuss
Hi,

I am struggling on this issue for over a month now. I do not know why you were not able to reproduce this bug. But if you could give me your public key, I can give you access to my system where I have configured this setup. 

Otto van der Schaaf

unread,
Jul 19, 2016, 5:17:48 AM7/19/16
to mod-pagespeed-discuss
Sorry about the delay. I have tried to figure out what happens with the routing here in PageSpeed myself but it is not easy.
I can reproduce it, and I'm working on a system test that fails on this problem so I can file a clear bug report on this on github. 
That should help others a lot with reproducing the problem. I'll update here when I have done so.

Otto

Otto van der Schaaf

unread,
Jul 22, 2016, 8:56:07 AM7/22/16
to mod-pagespeed-discuss
Updating this thread: filed an issue https://github.com/pagespeed/mod_pagespeed/issues/1361
Please subscribe to that issue if you want to get updated.

Pushed a branch with a failing system test for this:

Otto
Reply all
Reply to author
Forward
0 new messages