**********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