kujhg 发表于 2015-3-11 08:30:24

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_uses1;
         fastcgi_cache_use_stale error timeout invalid_header http_500;
         fastcgi_cache_key       $host$request_uri;
   }

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

页: [1]
查看完整版本: discuz头像程序解析结果缓存