Question

I have a directory with my media files and I need no to display them on other sites. Server doesn't support .htaccess, because it uses nginx.

How can I enable hotlink protection for my files?? Thank you.

Was it helpful?

Solution

Easiest way would be to check for the Referer header in HTTP request. Basically if that header does not have URL from your site, then this could be hot linking.

This has following problems:

  • Referrer header can be forged -> hot linking works
  • All user agents do not necessarily send the Referrer header -> legitimate user might not get the content.

You could also set a cookie when user is browsing your site, and check for existence of that cookie when user is accessing the streaming content.

OTHER TIPS

The details may be dated, but Igor gives an example of referrer mapping for image hotlink protection that might be useful here: http://nginx.org/pipermail/nginx/2007-June/001082.html

If you decide to go the referrer route.

If you are using memcached you could also store store client IP addresses for a time and only serve up your streaming media if an unexpired client IP is found in the cache. The client IP gets cached during normal browsing ensuring that the person viewing your streaming content has also recently been visiting your site.

On my hostgator site, they used nginx as a proxy to Apache(nginx+apache). maybe that will help you. Also if you have access to the logs, if you see a lot of traffic that way from a ip I would investigate, and if it points to a site, then block the other web server. Php's file_get_contents doesn't get stopped by htaccess or anything else I know besides blocking the ip.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top