2013-02-24 108 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