阻止热链接/访问mp4文件


Prevent hotlinking/access to mp4 files

我有一个用PHP创建的网站,在那里我通过flash播放器或html5播放器播放mp4文件。最近我看到我的文件也在其他网站上,这让我损失了带宽。

我在存储mp4文件的远程主机上使用httpd/apache。在网站上,我使用nginx。

我对PHP和MySQL有一些知识,但我不知道如何做到这一点。如何使它们只能通过我的网站访问?

示例1,阻止所有热链接(当可检测时(

location ~* ('.png)$ {
   valid_referers blocked mysite.com www.mysite.com;
   if ($invalid_referer) {
       return 405;
   }     
}    

示例2,重定向仅用于某些站点的热链接文件

location ~* ('.mp4)$ {
   if ($http_referer ~ ^(http://www.bad.com|http://stupid.com) ) {
       # Redirect to a specific file
       #rewrite  ^/(.*)$ http://mysite.com/dont-hotlink.html last; 
       # Redirect to a dynamic url where /hotlinked/ is some script that
       # displays some info about the hotlinked file.
       rewrite  ^/(.*)$ http://mysite.com/hotlinked/$1/ last; 
   }   
}

来源:使用nginx 重定向或阻止热链接文件