独立ip主机设置防盗链(适用vps云主机服务器)

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://faq.myhostadmin.net/faq/listagent.asp?unid=650 把伪静态组件开启

  2. 若是纯净版系统,请按http://faq.myhostadmin.net/faq/listagent.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;

        }

    }


}


相关产品: 异常流量清洗服务产品介绍


日期:2011-09-23

打印 】