Linux-CentOS XAMPP Apache 防盗链模块mod_auth_token的安装配置

本文介绍mod_auth_token模块的下载、编译过程,并详细展示了如何在httpd.conf及httpd-vhosts.conf中进行配置以实现文件路径到HTTP防盗链路径的转换。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【1】下载

https://code.google.com/p/mod-auth-token/



【2】编译

[plain]  view plain  copy
 print ?
  1. rm -f configure  
  2. autoreconf -fi  
  3. automake -f  
  4. ./configure  
  5. make  
【3】配置httpd.conf

是否添加

[plain]  view plain  copy
 print ?
  1. LoadModule auth_token_module  modules/mod_auth_token.so  
【4】配置httpd-vhosts.conf

假名preview指向mnt。

[plain]  view plain  copy
 print ?
  1. Alias /preview "/mnt"  
  2. <Location /preview/>   
  3.    AuthTokenSecret      "s3cr3tstr1ng"   
  4.    AuthTokenPrefix       /preview/  
  5.    AuthTokenTimeout     3600   
  6.    AuthTokenLimitByIp    on   
  7. </Location>  
【5】编码

传入系统文件的path,返回http协议的防盗链path

[php]  view plain  copy
 print ?
  1. public  static function get_auth_token_URI($sRelPath)  
  2.     {  
  3.         $secret        = "s3cr3tstr1ng";     // Same as AuthTokenSecret  
  4.         $protectedPath = "/preview/";        // Same as AuthTokenPrefix  
  5.         $ipLimitation  = true;               // Same as AuthTokenLimitByIp  
  6.         $hexTime       = dechex(time());     // Time in Hexadecimal  
  7.    
  8.         //  /mnt/volume1/2015/12/2/18/3/24637b61-a010-49cc-8c2d-6a0005abf2e5    
  9.         $fileName      = substr($sRelPath, 4); // The file to access  
  10.    
  11.         // Let's generate the token depending if we set AuthTokenLimitByIp  
  12.         if ($ipLimitation)  
  13.         {  
  14.             $token = md5($secret . $fileName . $hexTime . $_SERVER['REMOTE_ADDR']);  
  15.         }  
  16.         else  
  17.         {  
  18.             $token = md5($secret . $fileName$hexTime);  
  19.         }  
  20.    
  21.         // We build the url  
  22.         $httpOrigin = null;  
  23.         if(isset($_SERVER['HTTP_ORIGIN'] ))  
  24.             $httpOrigin = $_SERVER['HTTP_ORIGIN'];  
  25.         else  
  26.             $httpOrigin = 'http://' . $_SERVER['HTTP_HOST'];  
  27.    
  28.         $url = $httpOrigin . $protectedPath . $token"/" . $hexTime . $fileName;  
  29.         return $url;  
  30.     }  

转自 http://blog.youkuaiyun.com/aoshilang2249/article/details/50301505

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值