Hi Wim,

Just a quick one - we've got a bit of a complex setup, using squid to proxy our main server on another continent. We have two top level domains:

www.example.co.uk (UK server)
www.example.com (US and RoW - squid server)

We've set up CNAME DNS records for *.cdn.example.co.uk and *.cdn.example.com; I need to set CDN up in origin pull mode to grab resources not only from a particular hostname, but also from the right TLD. So for example:

0.cdn.example.co.uk| .jpg (IF ON THE UK SITE)
0.cdn.example.com| .jpg (IF ON THE US/RoW SITE)

I'm assuming I need to use the cdn_pick_server() function to use the right top level domain - but cannot figure out for the life of me how.

Any hints?

Any help hugely appreciated!!

Many thanks,
Jack.

Comments

wim leers’s picture

Assigned: Unassigned » wim leers
Status: Active » Postponed (maintainer needs more info)

How about this: define the variable that sets this (cdn_basic_mapping) in your settings.php file, create sites/example.co.uk/settings.php and sites/example.com/settings.php, and there you go! :)

essenceofginger’s picture

Status: Postponed (maintainer needs more info) » Active

Hi Wim, thanks for the reply.

Perhaps I didn't explain very well. There is only one sites/[sitename] folder as the .com is an exact mirror of the .co.uk - using squid proxy.

I thought about possibly using PHP to grab the hostname, and inserting that into the server array... but that said, I can't figure out for the life of me how to edit the server array anyway.

:(

essenceofginger’s picture

Just to clarify - content translations (with entity translation module) are served based on URL detection, in this case.

wim leers’s picture

Status: Active » Postponed (maintainer needs more info)

If it's a squid proxy serving the *exact* same content for both the .com and the .co.uk, then how are you serving domain-specific content? It seems you're not; the sites appear to be identical, both simply serve /en-uk and /en-us content?

essenceofginger’s picture

By using entity translation and locale. If the .com is detected in the request, then it serves up the US translation of the node instead of the UK. So yes, you're right, one serves /en and the other serves /en-us.

Here's an actual example:

http://www.brightpearl.co.uk/about-the-app/stock-control (here on in 'UK')
http://www.brightpearl.com/about-the-app/inventory (here on in 'US')

Notice the node ID attached as a class to the body tag. So as far as using the CDN module is concerned (this is only in testing mode by the way, so you'll have to take my word for it), this is how the masthead image is rewritten:

On the UK site:
http://3.cdn.brightpearl.co.uk/cdn/farfuture/dCjjDWU0EW3D2KKJ6swPAKSNZqB...

on the US site:
http://3.cdn.brightpearl.co.uk/cdn/farfuture/dCjjDWU0EW3D2KKJ6swPAKSNZqBnYc3Wyu6FsEzoeBY/mtime:1331086977/sites/default/files/masthead_productsandstock.jpg

Here's the CDN mapping from admin/config/development/cdn/details:

http://3.cdn.brightpearl.co.uk| .jpg .jpeg .png

So, as you can see, the .com site needs pull from 3.cdn.brightpearl.com, otherwise US visitors are grabbing content via a transatlantic hop. It's almost like i need to be able to specify that the CDN mapping is language specific (EN), and then create an EN-US alternative.

I can't get my head around this! Top notch module, by the way - it's made serving our content up by CDN so much easier. Hooking into the URL detection of the Locale module is the last piece of the puzzle.

essenceofginger’s picture

Hey Wim,

In case you or anyone else finds this useful, we got it working by adding some extra code into the body of cdn_pick_server(). Obviously in this instance it's only useful if you've got a .co.uk and a .com, but could be easily rewritten to add more.

$filename = basename($servers_for_file[0]['url']);
$unique_file_id = hexdec(substr(md5($filename), 0, 5));
$result = $servers_for_file[$unique_file_id % count($servers_for_file)];
if ('www.example.com' == $_SERVER['HTTP_HOST']) {
 $result['url'] = str_replace('.co.uk', '.com', $result['url']);
 $result['server'] = str_replace('.co.uk', '.com', $result['server']);
}
return $result;
wim leers’s picture

Status: Postponed (maintainer needs more info) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Anonymous’s picture

Issue summary: View changes

typo correction