好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Apache防盗链说明|/supesite/index.php-Apache教程

最近,大家都比较关心防盗链的问题,担心 安装 了SupeSite/X-Space之后,开通博客的朋友多了
他们上传的 图片 被盗链会造成 服务器 无谓的负担,现在我给大家讲解一下如何利用 apache 本身来防盗链 :)

首先,找到您的apache设置文件,
一般情况下在 /usr/local/apache/conf/httpd.conf
或者apache 2.2 的 /usr/local/apache2/conf/extra/httpd-vhost.conf
您可以酌情找到自己的conf文件,windows和freebsd下也一样,然后找到类似如下内容
QUOTE:
这个是带rewrite的

<VirtualHost *:80>
    DocumentRoot /home/www
    ServerNamewww.yourdomin.com
   <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^/supesite/([0-9]+)/spacelist(.*)$ /supesite/index. PHP ?$1/action_spacelist$2
    RewriteRule ^/supesite/([0-9]+)/viewspace_(.+)$ /supesite/index.php?$1/action_viewspace_itemid_$2
    RewriteRule ^/supesite/([0-9]+)/viewbbs_(.+)$ /supesite/index.php?$1/action_viewbbs_tid_$2
    RewriteRule ^/supesite/([0-9]+)/(.*)$ /supesite/index.php?$1/$2
    RewriteRule ^/supesite/([0-9]+)$ /supesite/index.php?$1
    RewriteRule ^/supesite/action_(.+)$ /supesite/index.php?action_$1
    RewriteRule ^/supesite/category_(.+)$ /supesite/index.php?action_category_catid_$1
    RewriteRule ^/supesite/itemlist_(.+)$ /supesite/index.php?action_itemlist_catid_$1
    RewriteRule ^/supesite/viewnews_(.+)$ /supesite/index.php?action_viewnews_itemid_$1
    RewriteRule ^/supesite/viewthread_(.+)$ /supesite/index.php?action_viewthread_tid_$1
    RewriteRule ^/supesite/index([.a-zA-Z0-9]*)$ /supesite/index.php
</IfModule>
</VirtualHost>
QUOTE:
这个是不带rewrite的

<VirtualHost *:80>
    DocumentRoot /home/www
    ServerNamewww.yourdomin.com
</VirtualHost>
在其中加入一段,具体内容如下:
QUOTE:
SetEnvIfNoCase Referer "^http://www.yourdomin.com" local_ref=1
SetEnvIfNoCase Referer "^http://yourdomin.com" local_ref=1
<FilesMatch ".(txt|doc|mp3|zip|rar|jpg|gif)">
Order Allow,Deny
Allow from env=local_ref
</FilesMatch>
其中红色的是您的网址,如果有多个,就加多行
绿色的是您需要防盗链的文件后缀,中间用|隔开

还一种写法,是用正则的,这种写法在各个版本的apache比较通用。

写法是
QUOTE:
SetEnvIfNoCase Referer "^http://.*.yourdomin.com" local_ref=1
SetEnvIfNoCase Referer ".*.yourdomin.com" local_ref=1
<FilesMatch ".(txt|doc|mp3|zip|rar|jpg|gif)">
Order Allow,Deny
Allow from env=local_ref
</FilesMatch>
其中红色的部分有一点区别,用正则写法,  符号代表转义,因为.本身在正则中有自己的作用。


最终改完就变成了
QUOTE:
<VirtualHost *:80>
    DocumentRoot /home/www
    ServerNamewww.yourdomin.com
    SetEnvIfNoCase Referer "^http://www.yourdomin.com" local_ref=1
    SetEnvIfNoCase Referer "^http://yourdomin.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
    RewriteRule ^/supesite/([0-9]+)/spacelist(.*)$ /supesite/index.php?$1/action_spacelist$2
    RewriteRule ^/supesite/([0-9]+)/viewspace_(.+)$ /supesite/index.php?$1/action_viewspace_itemid_$2 " Apache防盗链说明 "由 第二电脑网 原创提供,转载请注明: http://www.002pc.com/master/College/Server/Apache/18039.html

查看更多关于Apache防盗链说明|/supesite/index.php-Apache教程的详细内容...

  阅读:66次