FastDFS的作者介绍的防盗链 使用FastDFS的内置防盗链功能

FastDFS内置防盗链采用Token的方式。
token是带时效的,包含了文件ID、时间戳ts和密钥。
在设定的时间范围内,比如5分钟内,token是有效的。

FastDFS在URL中带上当前时间戳和带时效的token,参数名分别为ts和token。
FastDFS API中提供了生成token的算法,扩展模块中会对token进行检验。
token的生成和检验都在服务器端,因此不会存在安全问题。

链接示例:http://192.168.1.15:8080/group1/M01/01/01/wKgBD01c15nvKU1cAABAOeCdFS466570.c?token=b32cd06a53dea4376e43d71cc882f9cb&ts=1297930137

http.conf中防盗链相关的几个参数如下:
http.anti_steal.check_token:是否做token检查,缺省为false
http.anti_steal.token_ttl:token TTL,即生成token的有效时长
http.anti_steal.secret_key:生成token的密钥,尽量设置得长一些,千万不要泄露出去
http.anti_steal.token_check_fail:token检查失败,返回的文件内容,需指定本地文件名

配置示例如下:
# if use token to anti-steal
# default value is false (0)
http.anti_steal.check_token=false

# token TTL (time to live), seconds
# default value is 600
http.anti_steal.token_ttl=900

# secret key to generate anti-steal token
# this parameter must be set when http.anti_steal.check_token set to true
# the length of the secret key should not exceed 128 bytes
http.anti_steal.secret_key=FastDFS1234567890

# return the content of the file when check token fail
# default value is empty (no file sepecified)
http.anti_steal.token_check_fail=/home/yuqing/fastdfs/conf/anti-steal.jpg

posted on 2019-07-09 00:19  &大飞  阅读(765)  评论(0编辑  收藏  举报

导航