discuz头像程序解析结果缓存


论坛头像是动态的,例如:http://xxx.xxx.xxx/avatar.php?uid=xxx&size=big 

每个用户的头像文件都有big、middle、small三个,并且在不同场景分别调用不同尺寸的头像图片,比如帖子、个人设置、头像编辑、登陆等等场景,无形中增加了nginx与php之间的工作压力,如果能够把这个解析结果缓存起来,那么就会减少nginx与php的通信压力,会降低系统cpu使用率。


测试nginx缓存功能,配置如下:


http域添加

fastcgi_cache_path /xxxcache levels=1:2 keys_zone=cgicache:30m inactive=1d max_size=10g;


server域添加

    location ~* ^/avatar.php?.*$ {
        add_header X-Cache-CFC "$upstream_cache_status - $upstream_response_time";
        fastcgi_temp_path /xxxtemp;
        fastcgi_pass            127.0.0.1:9000;
        fastcgi_index           index.php;
        fastcgi_param           SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include                 fastcgi_params;
        fastcgi_cache           cgicache;
        fastcgi_cache_valid     301 302 1h;
        fastcgi_cache_min_uses  1;
        fastcgi_cache_use_stale error timeout invalid_header http_500;
        fastcgi_cache_key       $host$request_uri;
    }


通过验证,缓存文件生成成功,http请求换成miss、hit等状态正确。




本文出自 “菩提” 博客,请务必保留此出处http://zhangxingnan.blog.51cto.com/3241217/1619053

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。