環境:
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服務器時間不要相差分鍾級。