Nginx反向代理Redis服务

Nginx反向代理Redis服务

 

Nginx代理Redis

 

第一步:redis 配置及启动

vim redis.conf
port 6379
# bind 127.0.0.1
daemonize yes
requirepass test1234

redis-server /software/redis-5.0.5/redis.conf 

ps -ef |grep redis
root       2081      1  0 09:23 ?        00:00:07 redis-server *:6379

 

第二步:nginx 安装

./configure --with-stream    

#添加 stream 模块
make & make install

mv /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.bak
grep -vE '^#|^$|^    #|^        #' /usr/local/nginx/conf/nginx.conf.bak > /usr/local/nginx/conf/nginx.conf

vim /usr/local/nginx/conf/nginx.conf

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

stream {    # stream 模块配置和 http 模块在相同级别
    upstream redis {
        server 127.0.0.1:6379 max_fails=3 fail_timeout=30s;
    }
    server {
        listen 16379;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass redis;
    }
}


第三步:验证

端口验证:
netstat -ntlp |grep -E 'nginx|redis'
tcp        0      0 0.0.0.0:16379           0.0.0.0:*               LISTEN      13041/nginx: master 
tcp        0      0 0.0.0.0:6379            0.0.0.0:*               LISTEN      13253/redis-server  
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      13041/nginx: master 
tcp6       0      0 :::6379                 :::*                    LISTEN      13253/redis-server 

连接验证:
redis-cli -h 127.0.0.1 -p 16379
127.0.0.1:16379> auth "test1234"
OK


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值