CDN module produces incorrect absolute url's

Events happening in the community are now at Drupal community events on www.drupal.org.
stevenator's picture

Need some help putting together the CDN stuff that Christefano covered in the performance meetup from this past September at Oversee. I have basically done everything required nut am seeing some weird behavior.

I should actually start by saying that I have been researching CDN's and chose AWS Cloud Front. On November 1st they announced Custom Origins rather than having to use there default S3. This is now inline with the presentation (Christefano used SoftLayer) and works with the Basic mode of the CDN module. The File Conveyor by Wim Leers is not necessary.

You have to jump through a few hoops right now to enable it since their web GUI doesn't allow you to configure it. More information is available in the issues list for CDN at:

http://drupal.org/node/971234

Anyhow, I stepped through the instructions. I have a working Origin Pull CDN at AWS and I have confirmed it by putting in my CNAME generated domain: cdn.domain.com which show one of the images I pushed to the AWS node nearest me.

I also walked through the install instructions that include 2 patches for Drupal core and the Imagecache module. My problem is that Drupal is creating a wonky file path through the patched file_create_url() function that look like this:

http://domain.com/cdn.domain.com/cdn.domain.com/sites/domain.com/files/i...

I manually looked at all of the patches and everything looks good. Any ideas for why this might happen???

Comments

CDN good, other Modules bad

stevenator's picture

Well not quite so much. I found the solution to my problems and wanted to put it here for others. The answer had to do with using other modules along with CDN (a great addition to the Drupal world and bumped my site from a D to a B in Yslow).

After correctly applying the backported D7 patches for D6, I noticed that all of my custom theme and modules were working correctly. the problem remained in my combined use of the Image, Img_assist, and Pathologic modules which all make separate calls to the file_create_url() function in /includes/file.inc; this is a major part of the drupal6.patch).

Essentially all that was happening was that each time the path was called through these modules another occurance of the cdn domain was added to the path.

Solution (for me, you may be different but this is a basic approach): First make sure that the core patch is applied correctly at /admin/reports/status. Next disable Pathologic. Clear all caches at /admin/settings/performance or drush cc all. And that is what fixed my inline image filters. I reenabled Pathologic and everything is now playing nicely.

You can also read my comments on the CDN issues cue for more info.

Also many thanks to Wim Leers for his kick ass thesis and CDN module for the community. And an additional shout out to @rjbrown99 for the set up and call out to Amazon's new Cloudfront Origin Pull/Custom Origin services. This made everything really inline with a Drupal LA group presentation this past September on CDN's and the use of the CDN module in basic mode without having to install the File Conveyor Daemon to resolve Origin Push issues.

Sources:
Problems with shipped files and Drupal 6 file_create_url() behavior
Skip root-relative and protocol-relative URLs and support the Pathologic module
Non-filter URL rewriting

Thanks

rjbrown99's picture

Thanks, and rjbrown99 is also one of your local LA Drupal community members :) Feel free to ping me if you have questions, I'm happy to help.

One more thing

rjbrown99's picture

Oh - and don't forget about this patch: http://drupal.org/node/974992

Otherwise .JPG files won't come from your origin pull CDN. This fixes issues with caps vs. lowercase filenames.

Nice to hear your in LA

stevenator's picture

Make sure to introduce yourself next meetup or if you happen to be attending SandCamp.

And thanks for the heads up of the jpg case. If I get time I'll try to test the re-write url's in node body that Wim was asking about. I have another site that badly needs this and they have a ton of inline images without a filter on them. Should be fun!

CDN

rjbrown99's picture

It's working quite well for me with Cloudfront+Origin pull. I also did a bit of refactoring of my varnish config so any of the static content that is served up locally (like Javascript) comes out of the varnish cache. Overall CDN+Varnish has relegated my webserver into doing nothing but firing back the dynamic page output, which is the goal.

I don't have a lot of node body images so that's not a really big deal for me and my testing probably isn't going to reveal a lot. 99% of my stuff comes from imagefield/imagecache CCK fields.

I haven't been out to a meetup in a bit - the last one was one of the Santa Monica events @ CauseCast. I may try to come out to Culver City depending on my schedule.

Varnish Tweaks!

aruna.kulatunga's picture

Hi RJ,

I am assuming that you are not serving ajax related Jscripts through the CDN (Cross-Domain issue) and have some sub_vcl´s in the Varnish VCL to pass through these. I have the same issue and would love some help. Will it be possible to post your default.vcl?

Aruna