1,Apache的防盗链
编辑.htaccess文件,添加以下代码
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://www.domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://domain.com$ [NC]
RewriteCond %{HTTP_REFERER} !^http://domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://domain.com$ [NC]
RewriteRule .*.(gif|jpg|jpeg|png|bmp|swf|mp3|wav|zip|rar)$ http://www.domain.com/404.html [R,NC]


2,Nginx的防盗链
编辑网站配置文件.conf,添加以下代码
location ~ .*.(gif|jpg|jpeg|png|bmp|swf|mp3|wav|zip|rar)$
       {
           valid_referers none blocked domain.com
*.domain.com;
           if ($invalid_referer)
                   {
                      return 403;
                    }
            expires      30d;
         }
domain.com
替换为你的网址,重启nginx