Nginx 高级篇(五)Nginx 直连 Redis
redis2-nginx-module 是一个支持 Redis 2.0 协议的 Nginx upstream 模块,它可以让 Nginx 以非阻塞方式直接防问远方的 Redis 服务,同时支持 TCP 协议和 Unix Domain Socket 模式,并且可以启用强大的 Redis 连接池功能。详情见github https://github.com/openresty/redis2-nginx-module
假设你已经安装好了Nginx服务器
假设你已经安装好了Redis服务端
接下来我们下载安装redis2-nginx-module模块
下载地址:
https://github.com/openresty/redis2-nginx-...
//当然你可以下载最新版本哈
wget https://github.com/openresty/redis2-nginx-module/archive/v0.14.tar.gz
//解压
tar -zxvf v0.14.tar.gz
目前目录结构如下
cd nginx-1.10.1
接下来是重点—–编译nginx
./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/usr/local/redis2-nginx-module
有可能遇到这个报错,在centos上:
./configure: error: the HTTP rewrite module requires the PCRE library.
那就:
`yum ``install` `pcre-devel`
然后
make && make install
这样就安装好了
修改nginx.conf,就可以像README中描述的那样
# GET /get?key=some_key
location= /get {
set_unescape_uri $key $arg_key; # this requires ngx_set_misc
redis2_query get $key;
redis2_pass foo.com:6379;
}
# GET /set?key=one&val=first%20value
location= /set {
set_unescape_uri $key $arg_key; # this requires ngx_set_misc
set_unescape_uri $val $arg_val; # this requires ngx_set_misc
redis2_query set $key $val;
redis2_pass foo.com:6379;
}
下边代码供参考:
server {
location = /v1/qrcode/loginInfo {
default_type application/json;
redis2_query auth ${KVSTORE_AUTH};
redis2_query select ${KVSTORE_DB};
redis2_query get $arg_uuid;
redis2_pass redisPool;
}
}
Don’t think that others will clearly write the knowledge to you. If you don’t understand, go to Baidu yourself!
本作品采用《CC 协议》,转载必须注明作者和本文链接
推荐文章: