299

Apache服務器設置防盜鏈的方法

時間: 2015-05-12 11:00:40   點擊數(shù): 35744   來源: 耐思智慧

首先,找到您的apache設置文件,一般情況下在 /usr/local/apache/conf/httpd.conf或者apache 2.2 的 /usr/local/apache2/conf/extra/httpd-vhost.conf,您可以酌情找到自己的conf文件,windows和freebsd下也一樣,然后找到類似如下內(nèi)容:

這個是discuz X2.5自帶rewrite的規(guī)則

<VirtualHost *:80>

   DocumentRoot /home/www

   ServerName www.zhanhelp.com

  <IfModule mod_rewrite.c>

       RewriteEngine On

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/topic-(.+).html$ $1/portal.php?mod=topic&topicid=$2&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/article-([0-9]+)-([0-9]+).html$ $1/portal.php?mod=view&aid=$2&page=$3&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/forum-(w+)-([0-9]+).html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/group-([0-9]+)-([0-9]+).html$ $1/forum.php?mod=group&fid=$2&page=$3&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/space-(username|uid)-(.+).html$ $1/home.php?mod=space&$2=$3&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+).html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/(fid|tid)-([0-9]+).html$ $1/index.php?action=$2&value=$3&%1

</IfModule>

</VirtualHost>

這個是不帶rewrite的

<VirtualHost *:80>

   DocumentRoot /home/www

   ServerName www.zhanhelp.com

</VirtualHost>

在其中加入一段,具體內(nèi)容如下:

SetEnvIfNoCase Referer "^http://www.zhanehlp.com" local_ref=1

SetEnvIfNoCase Referer "^http://zhanehlp.com" local_ref=1

<FilesMatch ".(txt|doc|mp3|zip|rar|jpg|gif)">

Order Allow,Deny

Allow from env=local_ref

</FilesMatch>

其中站幫網(wǎng)的網(wǎng)站要更換成您的網(wǎng)址,如果有多個,就加多行;

txt|doc|mp3|zip|rar|jpg|gif的是您需要防盜鏈的文件后綴,中間用|隔開。


另外一種寫法,是用正則,這種寫法在各個版本的apache比較通用。具體寫法如下:

SetEnvIfNoCase Referer "^http://.*.zhanhelp.com" local_ref=1

SetEnvIfNoCase Referer ".*.zhanhelp.com" local_ref=1

<FilesMatch ".(txt|doc|mp3|zip|rar|jpg|gif)">

Order Allow,Deny

Allow from env=local_ref

</FilesMatch>

其中網(wǎng)址的部分有一點區(qū)別,用正則寫法, 符號代表轉義,因為.本身在正則中有自己的作用。


最終改完防盜鏈+偽靜態(tài)規(guī)則后就會變成如下:

<VirtualHost *:80>

   DocumentRoot /home/www

   ServerName www.zhanhelp.com

   SetEnvIfNoCase Referer "^http://bbs.zb7.com" local_ref=1

   SetEnvIfNoCase Referer "^http://zhanhelp.com" local_ref=1

  <FilesMatch ".(txt|doc|mp3|zip|rar|jpg|gif)">

      Order Allow,Deny

      Allow from env=local_ref

  </FilesMatch>

  <IfModule mod_rewrite.c>

       RewriteEngine On

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/topic-(.+).html$ $1/portal.php?mod=topic&topicid=$2&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/article-([0-9]+)-([0-9]+).html$ $1/portal.php?mod=view&aid=$2&page=$3&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/forum-(w+)-([0-9]+).html$ $1/forum.php?mod=forumdisplay&fid=$2&page=$3&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/forum.php?mod=viewthread&tid=$2&extra=page%3D$4&page=$3&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/group-([0-9]+)-([0-9]+).html$ $1/forum.php?mod=group&fid=$2&page=$3&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/space-(username|uid)-(.+).html$ $1/home.php?mod=space&$2=$3&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/blog-([0-9]+)-([0-9]+).html$ $1/home.php?mod=space&uid=$2&do=blog&id=$3&%1

       RewriteCond %{QUERY_STRING} ^(.*)$

       RewriteRule ^(.*)/(fid|tid)-([0-9]+).html$ $1/index.php?action=$2&value=$3&%1

</IfModule>

</VirtualHost>

現(xiàn)在你的網(wǎng)站就可以徹底的仿制盜鏈了。

上一篇:IIS服務器防盜鏈具體設置方法 下一篇:服務器的php.ini在哪

旗下網(wǎng)站:耐思智慧 - 淘域網(wǎng) - 我的400電話 - 中文域名:耐思尼克.cn 耐思尼克.top

耐思智慧 © 版權所有 Copyright © 2000-2024 www.testsystem.com.cn,Inc. All rights reserved

備案號碼: 粵ICP備09063828號  公安備案號: 公安備案 粵公網(wǎng)安備 44049002000123號  域名注冊服務機構許可:粵D3.1-20240003 CN域名代理自深圳萬維網(wǎng)

聲明:本網(wǎng)站中所使用到的其他各種版權內(nèi)容,包括但不限于文章、圖片、視頻、音頻、字體等內(nèi)容版權歸原作者所有,如權利所有人發(fā)現(xiàn),請及時告知,以便我們刪除版權內(nèi)容

本站程序界面、源代碼受相關法律保護, 未經(jīng)授權, 嚴禁使用; 耐思智慧 © 為我公司注冊商標, 未經(jīng)授權, 嚴禁使用

法律顧問:珠海知名律師 廣東篤行律師事務所 夏天風 律師