2013-02-24 82 views
0

我有一个用PHP创建的网站,我通过flash播放器或html5播放器播放mp4文件。最近我看到我的文件也在其他网站上,它花费我带宽。防止盗链/访问mp4文件

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

我在PHP和MySQL有一些知识,但我不知道如何做到这一点。我怎样才能让他们只能通过我的网站访问?

回答

2

例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; 
    } 
} 

来源: Redirect or block hotlinked files with nginx

+0

只要记住,HTTP参照网址是TRIVIAL伪造,而不是所有浏览器都发送给他们。这将有所帮助,但这不是一个魔术弹。另一方面,这是一个nginx解决方案,OP说他正在运行Apache ... – 2013-02-24 03:55:44

+0

hello, 谢谢你的回答。 我在存储mp4文件的主机上使用httpd。 也,如果我阻止盗链,会不会阻止从网站?网站和mp4文件不在同一个主机上。 – 2013-02-24 11:28:23