1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

两个apache节省流量技巧

本帖由 laogui2006-05-29 发布。版面名称:主机讨论

  1. laogui

    laogui Administrator
    管理成员

    注册:
    2005-08-30
    帖子:
    15,216
    赞:
    35
    防止baidu盗链mp3

    特征:
    HTTP refer中包含”mp3.baidu.com”和”m?ct=”关键字。(前者为baidu的mp3索引爬虫,后者为实际的下载连接)
    代码:
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} mp3\.baidu\.com [NC,OR]
    RewriteCond %{HTTP_REFERER} m\?ct=
    RewriteRule .* - [F]
    防止使用过多线程同时下载

    我使用了针对Apache 2的mod_limitipconn模块来限制单一IP的mp3文件的并发下载数为2。
    安装很简单,大家可以参考这篇: Linux下Apache并发连接数和带宽控制。把相关的配置加在httpd.conf的虚拟主机部分就起作用了:
    代码:
    <VirtualHost 202.104.238.145>
       DocumentRoot /usr/wwwroot/chinahtml/html
       ServerAdmin [email protected]
       DirectoryIndex index.html index.php
       ServerName www.chinahtml.com
       ServerAlias chinahtml.com
       ErrorLog /var/log/httpd/chinahtml/error_log
       CustomLog "|/usr/bin/cronolog /var/log/httpd/chinahtml/access_log.%Y%m%d" combined
       HostNameLookups off
    
       <Directory "/usr/wwwroot/chinahtml/html">
          AllowOverride All
       </Directory>
    
       <IfModule mod_limitipconn.c>
            <Location /podcast/srx>
                    MaxConnPerIP 2
                    OnlyIPLimit audio/mpeg
            </Location>
        </IfModule>
    
    </VirtualHost> 
    另外提醒一句,不要忘记打开前面的”ExtendedStatus On”,这样这个模组才会起作用。
     
  2. OUYANG

    OUYANG New Member

    注册:
    2005-09-06
    帖子:
    3,025
    赞:
    5
    学到刚好用到