9.nginx使用redis用缓存

需要使用到的第三方模块,因为在有道笔记上面,所以为办法直接给你们,需要的话给我私信或者邮件(913956964@qq.com)

 

1.编译安装,添加上述扩展插件
./configure --prefix=/usr/local/nginx --without-http_memcached_module --user=www --group=www --with-http_stub_status_module --with-openssl=/usr/ --with-pcre=/usr/local/src/pcre-8.31 --with-http_stub_status_module --add-module=/usr/local/src/ngx_devel_kit-master --add-module=/usr/local/src/set-misc-nginx-module-0.29 --add-module=/usr/local/src/srcache-nginx-module-0.30 --add-module=/usr/local/src/redis2-nginx-module-0.12 --add-module=/usr/local/src/echo-nginx-module-0.58
 
2.修改nginx.conf配置
location ~ .*\.php {
  root html;
                srcache_store_private on;
                srcache_methods GET;
                srcache_response_cache_control off;
   
                if ($uri ~ .*\.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;
 }
                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;
                redis2_pass 127.0.0.1:6379;
        }
 
        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 127.0.0.1:6379;
        }
 
3.redis检查是否产生key值
redis-cli
keys *
info
dbsize

 

posted @ 2016-01-29 15:29  Goun  阅读(1907)  评论(0编辑  收藏  举报