獨立ip主機設置防盜鏈(適用vps雲主機服務器)

發佈時間:2011-09-23

apache實現防盜鏈:

添加到.htaccess 文件中
RewriteEngine on 

RewriteCond %{HTTP_REFERER} !baidu.com [NC]

RewriteCond %{HTTP_REFERER} !google.com [NC]

RewriteCond %{HTTP_REFERER} !xxx.net [NC]

RewriteRule .*\.(jpg|jpeg|png|gif|bmp|swf|mp4|mp3|zip|rar|pdf|webp|js|css)$ /band.txt [NC,L]



iis6實現防盜鏈:


  1. 若是安裝了我司助手環境請先按http://www.west.cn/faq/list.asp?unid=650 把偽靜態組件開啓

  2. 若是純淨版系統,請按http://www.west.cn/faq/list.asp?unid=639 把偽靜態組件開啓

    然後在配置文件中按以下系統規則配置

進入others/httpd.conf中,保留前兩行,複製以下規則保存即可

RewriteEngine on 

RewriteCond %{HTTP_REFERER} !baidu.com [NC]

RewriteCond %{HTTP_REFERER} !google.com [NC]

RewriteCond %{HTTP_REFERER} !xxx.net [NC]

RewriteRule .*\.(jpg|jpeg|png|gif|bmp|swf|mp4|mp3|zip|rar|pdf|webp|js|css)$ /band.txt [NC,L]


xxx.net是您自己的域名

band.txt是被盜鏈後的提示內容文件


iis7+實現防盜鏈:

使用url-rewrite模塊實現,模塊下載地址 https://www.iis.net/downloads/microsoft/url-rewrite

在網站根目錄wwwroot下創建一個web.config文件,複製以下代碼保存即可, 如果網站有設置偽靜態,已存在web.config,則只複製中間顏色部分代碼,加到第一個<rules>之後即可

<?xml version="1.0" ?>

<configuration>
 <system.webServer>  
  <rewrite>  
   <rules>   

    <rule name="Prevent hotlinking">  

     <match url="^.*\.(jpg|jpeg|png|gif|bmp|swf|mp4|mp3|zip|rar|pdf|webp|js|css)$" ignoreCase="true" />  

      <conditions>  

       <add input="{HTTP_REFERER}" pattern="http://www.xxxxxx.com/.*" negate="true" />  

       <add input="{HTTP_REFERER}" pattern="http://xxxxxx.com/.*" negate="true" /> 

      </conditions>  

     <action type="Rewrite" url="/404.html" />  

    </rule>

   </rules>  
  </rewrite>  
 </system.webServer> 
</configuration>


nginx實現防盜鏈:

參考添加靜態文件的location配置

server {

    listen 80;

    server_name www.yoursite.com;


    # 定位到圖片等靜態資源

    location ~ .*\.(jpg|jpeg|png|gif|bmp|swf|mp4|mp3|zip|rar|pdf|webp|js|css)$

    {

        expires      30d;

        access_log /dev/null;

        valid_referers *.yoursite.com yoursite.com;

        if ($invalid_referer){

           return 444;

        }

    }


}


相關產品: 異常流量清洗服務產品介紹