Search code examples
nginxhotlinking

How to prevent hotlinking of streaming content?


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.


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.