您的位置:首页 > 运维架构 > Apache

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

2016-11-11 19:27 1256 查看
【1】下载

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



【2】编译

[plain] view
plain copy

 print?

rm -f configure  

autoreconf -fi  

automake -f  

./configure  

make  

【3】配置httpd.conf

是否添加

[plain] view
plain copy

 print?

LoadModule auth_token_module  modules/mod_auth_token.so  

【4】配置httpd-vhosts.conf

假名preview指向mnt。

[plain] view
plain copy

 print?

Alias /preview "/mnt"  

<Location /preview/>   

   AuthTokenSecret      "s3cr3tstr1ng"   

   AuthTokenPrefix       /preview/  

   AuthTokenTimeout     3600   

   AuthTokenLimitByIp    on   

</Location>  

【5】编码

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

[php] view
plain copy

 print?

public  static function get_auth_token_URI($sRelPath)  

    {  

        $secret        = "s3cr3tstr1ng";     // Same as AuthTokenSecret  

        $protectedPath = "/preview/";        // Same as AuthTokenPrefix  

        $ipLimitation  = true;               // Same as AuthTokenLimitByIp  

        $hexTime       = dechex(time());     // Time in Hexadecimal  

   

        //  /mnt/volume1/2015/12/2/18/3/24637b61-a010-49cc-8c2d-6a0005abf2e5    

        $fileName      = substr($sRelPath, 4); // The file to access  

   

        // Let's generate the token depending if we set AuthTokenLimitByIp  

        if ($ipLimitation)  

        {  

            $token = md5($secret . $fileName . $hexTime . $_SERVER['REMOTE_ADDR']);  

        }  

        else  

        {  

            $token = md5($secret . $fileName. $hexTime);  

        }  

   

        // We build the url  

        $httpOrigin = null;  

        if(isset($_SERVER['HTTP_ORIGIN'] ))  

            $httpOrigin = $_SERVER['HTTP_ORIGIN'];  

        else  

            $httpOrigin = 'http://' . $_SERVER['HTTP_HOST'];  

   

        $url = $httpOrigin . $protectedPath . $token. "/" . $hexTime . $fileName;  

        return $url;  

    }  



转自 http://blog.csdn.net/aoshilang2249/article/details/50301505
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: