lighttpd学习–使用mod_secdownload模块防盗链及fastcgi模式配置 ZT
来源:互联网 发布:ubuntu开启网络服务 编辑:程序博客网 时间:2024/06/06 05:19
最近应用端要配置出防盗链来,早就知道可以通过referer来判断是否是盗链,从而设置防盗链,然后我们开发的人员跟我说了lighttpd的另外有个模块可以来配置出防盗链来,这个模块就是mod_secdownload,这个模块的使用思路是,lighttpd端先配置此模块,设置一个固定的用于加密的字串,比如abc,然后设置一个url前缀,比如/flv/,再设置一个过期时间,比如10s,然后在通过一段php代码,对加密字串,系统时间等进行md5算法加密生成一个字串,这个字串在和url前缀组合生成最终的文件url,这个url会在10s后自动失效,从而达到防盗链的效果。原理就是这些,下面看下实际的例子。
因为需要php的支持,所以fastcgi的配置在这里就一并写出了,至于lighttpd和php的编译安装这里就不在赘述,需要的朋友请去google查询。有一点需要注意的就是php编译的时候需要启用fastcgi模式。
编辑配置文件,找到server.modules处,开启如下两个模块
先配置secdownload模块,如下
secdownload.secret = "abc" #设置需要的加密字串
secdownload.document-root = "/data/wwwroot" #需要防盗链文件的所在目录
secdownload.uri-prefix = "/flv/" #生成后url的前缀
secdownload.timeout = 20 #设置过期时间,单位秒
再来看下fastcgi模式的配置,我个人认为真的是太方便了。
## read fastcgi.txt for more info
## for PHP don’t forget to set cgi.fix_pathinfo = 1 in the php.ini
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"host" => "127.0.0.1", #设置fastcgi服务监听的ip
"port" => 9000, #设置fastcgi服务监听的端口
"bin-path" => "/usr/local/php/bin/php-cgi" #php-cgi所在的路径
)
)
)
到此,lighttpd上的配置就完毕了,然后看下php程序的写法
<?php
$secret = "abc";
$uri_prefix = "/flv/";
# filename
# please note file name starts with "/"
$f = "/123.mp4";
# current timestamp
$t = time();
$t_hex = sprintf("%08x", $t);
$m = md5($secret.$f.$t_hex);
# generate link
$videoUrl = $uri_prefix.$m."/".$t_hex.$f;
?>
这里$videoUrl就应该是最后生成出来的url
现在就可以启动lighttpd去测试了,启动lighttpd后执行ps afx可以看到如下内容,表示启动正常,如果不正常,请参看errorlog来排查错误
7179 ? Ss 0:00 _ /usr/local/php/bin/php-cgi
7180 ? S 0:00 | _ /usr/local/php/bin/php-cgi
7181 ? Ss 0:00 _ /usr/local/php/bin/php-cgi
7182 ? S 0:00 | _ /usr/local/php/bin/php-cgi
7183 ? Ss 0:00 _ /usr/local/php/bin/php-cgi
7184 ? S 0:00 | _ /usr/local/php/bin/php-cgi
7185 ? Ss 0:00 _ /usr/local/php/bin/php-cgi
7186 ? S 0:00 _ /usr/local/php/bin/php-cgi
参考资料:
http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModSecDownload
http://redmine.lighttpd.net/projects/lighttpd/wiki/Docs:ModFastCGI
- lighttpd学习–使用mod_secdownload模块防盗链及fastcgi模式配置 ZT
- Lighttpd 配置fastcgi
- Lighttpd fastcgi相关配置
- srs之防盗链配置及使用
- 探索lighttpd用fastcgi模式访问django
- lighttpd fastcgi
- windows下使用lighttpd+php(fastcgi)+mysql
- nginx FastCGI模块(FastCGI)配置
- linux安装lighttpd及配置lighttpd
- linux安装lighttpd及配置lighttpd .
- nginx配置防盗链及伪静态
- fdfs防盗链配置及java开发
- nginx+php的配置(使用nginx的fastcgi模块)
- Windows7系统下使用IIS7与FastCGI模块配置PHP
- 安装配置Linux+lighttpd+mysql+PHP(FastCGI)
- RedHat 上安装 lighttpd 并配置 fastcgi + django 的记录
- lighttpd fastcgi配置例子和一些备份脚本
- 安装配置Linux+lighttpd+mysql+PHP(FastCGI)
- Linux 平台下 JDK安装 TOMCAT安装(解压版) 启动 POSTGRESQL安装 启动 jboss安装
- 关于母版页的问题做一下小记录!
- MPEG2 TS小结
- Windows网络编程细节问题
- Female palace is studied and the construction
- lighttpd学习–使用mod_secdownload模块防盗链及fastcgi模式配置 ZT
- HTML/CSS对浏览器的判断
- 服务是社会趋势
- 如何调试和使用ActiveX控件
- 数据库的一些例子及其分析
- WINCE流驱动的动态加载调试与用EVC快速开发WINCE的流驱动(转)
- ECshop数据结构
- 查找指定文件夹下的文件
- mmc无法创建管理单元