Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I’m hosting a bunch of photos on Amazon S3 and also running Amazon CloudFront for them. Also, I’m running a custom domain name. Now, in case someone tries to embed the image to another website, I’d like to show a "This image is hosted on domain X" instead of the actual image.

Is this possible with the current setup I’ve described?

Whether this is a good idea or not, is not really a question, I just need to see if it’s even possible.

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

Cloudfront does not support the referrer header, so you can't directly do this. One approach to dealing with hotlinking though, is to generate signed URLs that expire after a short time. Essentially, with a dynamic page, you make all your Cloudfront content private, and then use a signed URL to embed the image in your page. The signed URL grants access to the content - either for a short period of time, or for a particular IP address. This essentially makes hotlinking impractical - as someone would need to constantly scrape your site for the new, valid, URLs. Of course, this has implications on caching. You could, alternatively, have the URL valid for a little over a day and regenerate the URL daily, instead of every page load.

share|improve this answer
    
Ok, sounds reasonable, thanks for the answer and I’ll try it out in the future if I really need to go down that path. –  margusholland Feb 21 '12 at 12:18
add comment

If CloudFront supports request rewriting based on the Referer: header, then yes. If it doesn't, then you'll need to put a web server that does between the public and your images. Apache/nginx both support this, as do most others that I'm aware of.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.