srcache_nginx+redis构建缓存系统
来源:互联网 发布:js实现购物车删除功能 编辑:程序博客网 时间:2024/06/04 23:19
在《memc_nginx+srcache_nginx+memcached构建透明的动态页面缓存》一文中,我们使用到memcached来作为缓存载体。想必大家都知道memcached有存储大小的限制,不得超过1M。 本文将使用redis来作为缓存载体。nginx的srcache_nginx模块指令参数解释参见《memc_nginx+srcache_nginx+memcached构建透明的动态页面缓存》。
1. nginx模块
--add-module=../modules/ngx_devel_kit-0.2.18 --add-module=../modules/set-misc-nginx-module-0.22rc8 --add-module=../modules/srcache-nginx-module-0.22 --add-module=../modules/redis-nginx-module-0.3.6 --add-module=../modules/redis2-nginx-module-0.10
nginx模块安装参见ttlsa.com中相关文档。
2. redis安装配置
安装步骤参见:http://www.ttlsa.com/html/1646.html
配置参数解释参见:http://www.ttlsa.com/html/1226.html
配置实例:
# vim redis.conf
daemonize yespidfile /var/run/redis-6379.pidport 6379bind 127.0.0.1timeout 0tcp-keepalive 0loglevel noticelogfile stdoutdatabases 16stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbslave-serve-stale-data yesslave-read-only yesrepl-disable-tcp-nodelay noslave-priority 100maxmemory 8096mbmaxmemory-policy volatile-ttlappendonly noappendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mblua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-entries 512list-max-ziplist-value 64set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64activerehashing yesclient-output-buffer-limit normal 0 0 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes
由于只把redis当做缓存使用,因此没有启用持久化。
3. nginx配置
# vim nginx.conf
http{ include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '"$status" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for" ' '"$gzip_ratio" $request_time $bytes_sent $request_length'; log_format srcache_log '$remote_addr - $remote_user [$time_local] "$request" ' '"$status" $body_bytes_sent $request_time $bytes_sent $request_length ' '[$upstream_response_time] [$srcache_fetch_status] [$srcache_store_status] [$srcache_expire]'; set_real_ip_from 10.0.0.0/8; real_ip_header X-Forwarded-For; include vhosts/test.ttlsa.com.conf;}
# vim vhosts/test.ttlsa.com.conf
upstream redis { server 127.0.0.1:6379; keepalive 512;}server { listen 80; server_name test.ttlsa.com; index index.html index.htm index.php; root /data/test.ttlsa.com/webroot; location ~ .*\.php { srcache_store_private on; srcache_methods GET; srcache_response_cache_control off; if ($uri ~ /ttlsa.com/pp.php$){ set $key $request_uri; set_escape_uri $escaped_key $key; srcache_fetch GET /redis $key; srcache_default_expire 172800; srcache_store PUT /redis2 key=$escaped_key&exptime=$srcache_expire; #add_header X-Cached-From $srcache_fetch_status; #set_md5 $md5key $key; #add_header X-md5-key $md5key; #add_header X-Cached-Store $srcache_store_status; #add_header X-Key $key; #add_header X-Query_String $query_string; #add_header X-expire $srcache_expire;access_log /data/httplogs/test.ttlsa.com-photo-access.log srcache_log; } include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_connect_timeout 60; fastcgi_send_timeout 180; fastcgi_read_timeout 180; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; } location = /redis { internal; set_md5 $redis_key $args; redis_pass redis; } location = /redis2 { internal; set_unescape_uri $exptime $arg_exptime; set_unescape_uri $key $arg_key; set_md5 $key; redis2_query set $key $echo_request_body; redis2_query expire $key $exptime; redis2_pass redis; } error_log /data/httplogs/test.ttlsa.com-error.log; access_log /data/httplogs/test.ttlsa.com-aceess.log main;}
4. 测试
没有做缓存状态:
有做缓存状态:
5. 响应头状态
第一次请求:
再次请求:
6. 查看redis是否缓存以及过期时间
如需转载请注明出处: http://www.ttlsa.com/html/3156.html
0 0
- srcache_nginx+redis构建缓存系统
- memc_nginx+srcache_nginx+memcached构建透明的动态页面缓存
- memc_nginx+srcache_nginx+memcached构建透明的动态页面缓存
- 缓存系统之Redis
- 使用redis构建文章投票系统
- 构建高性能数据库缓存之redis主从复制
- 构建高性能数据库缓存之Redis(一)
- redis+spring+maven构建项目(带有缓存)
- 构建高性能数据库缓存之redis主从复制
- 构建高性能数据库缓存之redis主从复制
- 构建高性能数据库缓存之redis主从复制
- 分布式缓存系统Redis安装和使用
- Memcached和Redis数据缓存系统
- 十、NOSQL与缓存系统-Redis安装
- 如何使用bloomfilter构建大型Java缓存系统
- 系统优化总结(2)----构建两级缓存
- 【转载】在Windows下Memcache缓存系统构建(Java)
- 手游服务端框架之使用Guava构建缓存系统
- 日经春秋 20150126
- ubuntu下,adb devices显示"???????????? no permissions"
- 初创企业获得成功的几点经验
- cortex_m3_stm32嵌入式学习笔记(二十):IIC实验(I2C串行总线)
- Java学习拾遗
- srcache_nginx+redis构建缓存系统
- Smarty 获取数组的长度
- 三种数据库的jdbc配置
- Java性能小技巧
- [leetcode] 30 Substring with Concatenation of All Words
- 安卓在代码中设置TextView的drawableLeft、drawableRight、drawableTop、drawableBottom
- jquery mobile 新手问题汇总
- 日经社説 20150126 中国は資源輸出の是正急げ
- Java之旅——字符串操作1