0

我有一个用 PHP 创建的网站,我通过 Flash 播放器或 html5 播放器播放 mp4 文件。最近我发现我的文件也在其他网站上,这占用了我的带宽。

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

我对 PHP 和 MySQL 有一些了解,但我不知道该怎么做。我怎样才能让它们只能通过我的网站访问?

4

1 回答 1

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

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

于 2013-02-24T03:08:25.590 回答