zyllf2009 发表于 2015-9-10 09:54:04

fastdfs 开启 token 防盗链

  环境:
  fastdfs
  nginx + ngx_fastdfs_module
  php+fastdfs_php扩展
  开启token令牌:
  vi /etc/fdfs/http.conf
  #开启
  http.anti_steal.check_token=true
  #密钥
  http.anti_steal.secret_key=123456
  重启nginx
  php中,通过fastdfs_http_gen_token()函数生成$token,例如:
  $ts=time();//当前时间戳
$token=fastdfs_http_gen_token('M00/00/00/Ss_0rVGSABmAEZ1QAAC6WE5-JkI695.zip',$ts);
  然后url形如:
  http://localhost/M00/00/00/Ss_0rVGSABmAEZ1QAAC6WE5-JkI695.zip?token=8de0e6554be69d0b9385faad654c4364&ts=1368589809
  这样服务端就可以自动根据 token , ts ,以及设置的密钥来验证合法性。密钥过期时间在http.conf里设置。
  问题:
  token总是验证失败,需要检查如下:
  1.fastdfs_http_gen_token($file_name,$timestmp);中$file_name 不要包含group_name
  2.你是否忘记设置客户端对应的配置文件里,也有一个密钥,要求跟http.conf中的一直,比如php.ini中的fastdfs_client.http.anti_steal_secret_key参数。
  3.检查你的fdfs服务器和client服务器时间不要相差分钟级。
页: [1]
查看完整版本: fastdfs 开启 token 防盗链