fastDFS token有效性配置说明

来源:互联网 发布:ubuntu 配置openstack 编辑:程序博客网 时间:2024/06/06 18:54

tracker上关于token的配置/etc/fdfs/http.conf :

# if use token to anti-steal
# default value is false (0)
http.anti_steal.check_token=true


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


# 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/storage/anti-steal.jpg

在tracker中配置token的有效时长为60s

在storage中关于token的配置/etc/fdfs/http.conf :

# if use token to anti-steal
# default value is false (0)
http.anti_steal.check_token=true


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


# 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/storage/anti-steal.jpg

在storage中配置token的有效时长为60s

这个只是在fastDFS中配置token的有效时长,其实配置时一般会在nginx上打开cache,即使fastDFS上token的有效时长已过,但在nginx上的cache还有缓存,这时去访问图片等资源时,还是从nginx(tracker上)的缓存中取。我们访问的文件的入口就是nginx,所以会优先查找nginx的cache。如果在tracker上的cache中没找到,再去storage上查找,storage判断token是否失效,如果没失效就返回资源信息,失效就返回配置的错误的页面。

再来看看nginx的cache配置:

proxy_buffer_size 16k;
    proxy_buffers 4 64k;
    proxy_busy_buffers_size 128k;
    proxy_cache_path /fastdfs/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:500m max_size=10ginactive=30d;
    proxy_temp_file_write_size 128k; #设置缓存存储路径、存储方式、分配内存大小、磁盘最大空间、缓存期限
    proxy_temp_path /fastdfs/cache/nginx/proxy_cache/tmp;

 location /g2/M00 {
            proxy_next_upstream http_502 http_504 error timeout invalid_header; proxy_cache http-cache;
            proxy_cache_valid 200 304 12h;
            proxy_cache_key $uri$is_args$args;
            proxy_pass http://fdfs_group2;
            expires 30d;
        }

配置为cache的期限为30天,文件会在tracker上保存30天再失效。

PS:

修改了/etc/fdfs/http.conf的配置,即使重启了storage(fdfs_storaged /etc/fdfs/storage.conf restart),但还需要重启nginx才能生效 (/usr/local/nginx/sbin/nginx -s stop;/usr/local/nginx/sbin/nginx)。

原创粉丝点击