温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

discuz头像程序解析结果缓存

发布时间:2020-07-05 15:42:01 来源:网络 阅读:1215 作者:zhangxingnan 栏目:web开发


论坛头像是动态的,例如: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等状态正确。


其它动态程序也可以使用此方法缓存。


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI