Forum

Questions and discussions

CNAME implementation

At Rackspace clouds hosting and Amazon S3

CNAME implementation

Postby Spectral » Thu Nov 17, 2011 6:11 pm

CNAME Implementation for Amazon S3.

Anton, please correct me if I produce some problems with this in your script….

The following procedure makes your thumbs and images stored on Amazon S3 available under a subdomain name of your own domain instead of the amazonaws domain.
Before you have to have a URL like:
http://bucket-previews.s3.amazonaws.com/8373_thumb2.jpg
After you can get the thumb via:
http://image-previews.yourdomain.com/8373_thumb2.jpg

It is a workaround for this Method:
http://carltonbale.com/how-to-alias-a-d ... -amazon-s3

You cannot apply the official Amazon way to do it directly, but you have to change some lines in the script before as explained below...

Needless to say that this may affect your page rankings and images (e.g. of the image search in a search engine) are getting easier associated with your domain.

The Problem with the Google image search is also described here:
http://www.starkui.com/2011/10/seo-usin ... th-images/

The script will continue to point to the amazonaws domain, so the implementation is just an alternate way. Anton will have to help us out so that the scripts database links are pointing to the CNAME domain instead of the amazonaws link….

Until now everything seems to work fine, but I am not 100% sure if I mess up anything with this method, so if anyone understands the cloud implementation better and sees some errors in my method, please correct me!

PART 1 - Script changes:

Change the following lines in the file /members/cron_amazon.php:
Code: Select all
$bucket_files = $site_amazon_prefix. "-files";
   //$container_files = $s3->create_bucket($bucket_files,$region);
   
   $bucket_previews = $site_amazon_prefix. "-previews";
   //$container_previews = $s3->create_bucket($bucket_previews,$region);


to

Code: Select all
   $bucket_files = $site_amazon_prefix. "-files.YOURDOMAIN.COM";
   //$container_files = $s3->create_bucket($bucket_files,$region);
   
   $bucket_previews = $site_amazon_prefix. "-previews.YOURDOMAIN:COM";
   //$container_previews = $s3->create_bucket($bucket_previews,$region);


In the file /admin/storage/amazon_test.php:
Code: Select all
// Determine a completely unique bucket name (all lowercase)
   $bucket = $site_amazon_prefix. "-test";
   $bucket_files = $site_amazon_prefix. "-files";
   $bucket_previews = $site_amazon_prefix. "-previews";

to

Code: Select all
// Determine a completely unique bucket name (all lowercase)
   $bucket = $site_amazon_prefix. "-test.YOURDOMAIN.COM";
   $bucket_files = $site_amazon_prefix. "-files.YOURDOMAIN.COM";
   $bucket_previews = $site_amazon_prefix. "-previews";


In the file /admin/storage/amazon.php:
Code: Select all
<p>
<b>[PREFIX]-files</b> - for the files.<br>
<b>[PREFIX]-previews</b> - for the previews.
</p>


to
Code: Select all
<p>
<b>[PREFIX]-files.YOURDOMAIN.com</b> - for the files.<br>
<b>[PREFIX]-previews.YOURDOMAIN.com</b> - for the previews.
</p>


Part 2 - Test your settings:
- Get and install a Amazon S3 tool like the Firefox plugin S3Fox Organizer (http://www.s3fox.net/) and access your amazon storage to see if the correct files are created.
- Go to the admin area of your script: Settings>File storage>Amazon S3
- Rename your Bucket in the prefix field as you wish (if necessary) and push "change"
- Push "Test"
- See in the S3fox if the folders are created correctly (don't forget to reload).
There should be now 3 folders:
"yourbucket-test.yourdomain.com"
"yourbucket-files.yourdomain.com"
"yourbucket-previews.yourdomain.com"
- if so, continue to step 3

Part 3 - Server changes:
Now you have to change the DNS settings in your Server and configure a CNAME.
If you use CPANEL the easiest way is via the "Simple DNS Zone Editor" in your admin area:
Leave the "A record" area blank.
Where it says "Add a CNAME Record" :
Name: yourbucket-previews (it should get auto-completed to "yourbucket-previews.yourdomain.com.")
CNAME: yourbucket-previews.yourdomain.com.s3.amazonaws.com
Push "add"

Again for the -Files:
Name: yourbucket-files (it should get auto-completed to "yourbucket-previews.yourdomain.com.")
CNAME: yourbucket-files.yourdomain.com.s3.amazonaws.com
Push "add"

Afterwards you should have two new entries like this:
yourbucket-previews.yourdomain.com. CNAME yourbucket-previews.yourdomain.com.s3.amazonaws.com
yourbucket-files.yourdomain.com. CNAME yourbucket-files.yourdomain.com.s3.amazonaws.com

Part 4 - Testing and Waiting:
Wait three minutes and check if your CNAME entries are correct. Check with sites like this:
http://www.mxtoolbox.com/
http://www.samdns.com/
The domain yourbucket-files.yourdomain.com should now refer correctly to yourbucket-files.yourdomain.com.s3.amazonaws.com.

In the S3Fox you should be able to see newly uploaded files appearing in the created buckets…

PLEASE NOTE THAT IT ALWAYS TAKES UP TO 24 hrs UNTIL THE DNS SERVERS ARE UPDATED!
THE NEW SETTINGS ARE ONLY VALID FOR NEWLY UPLOADED FILES, NOT FOR EXISTING ONES!
When the new DNS settings are active, you can now open any newly uploaded image file via "view image" in your browser….where it says e.g. "http://yourbucket-previews.yourdomain.com.s3.amazonaws.com/7538_thumb2.jpg" you should now be able to view your image via the URL "http://yourbucket-previews.yourdomain.com/7538_thumb2.jpg"

If so, you are done :-)
Spectral
 
Posts: 14
Joined: Fri Mar 11, 2011 6:19 pm

Return to Remote file storage

Who is online

Users browsing this forum: No registered users and 2 guests

  Photo Store Script

Professional php photo stock script and WordPress plug-in for photographers and video producers.

  Support
  CMSaccount Inc.