nginx redis php,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

目前目录结构如下

19fd9de4acb16ce0f9cfedf9a52f484c.png

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 协议》,转载必须注明作者和本文链接

胡军

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值