原理圖:
服務器:
反向代理服務器 nginx:
IP: 192.168.1.190
Web服務器 兩臺 apache
Apache1:
配置:apache + php (php安裝redis擴展)
IP: 192.168.1.191
Apache2:
配置:apache + php (php安裝redis擴展)
IP: 192.168.1.192
緩存服務器 redis:
IP: 192.168.1.6
配置:
Nginx配置文件 : nginx.conf
主要配置代碼:
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user[$time_local] "$request" '
# '$status $body_bytes_sent"$http_referer" '
# '"$http_user_agent""$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
# 反向代理 lihao.test.nginx.jifenyun.com爲域名
upstream lihao.test.nginx.jifenyun.com {
server192.168.1.191:80 weight=10; #apache1 weight 代表權重設置
server192.168.1.192:80 weight=10; # apache2 weight 代表權重設置
}
#gzip on;
server {
listen 80;
server_name lihao.test.nginx.jifenyun.com;
#charsetkoi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm index.php;
proxy_passhttp://lihao.test.nginx.jifenyun.com;
proxy_set_headerHost $host;
proxy_set_headerX-Real-IP $remote_addr;
proxy_set_headerX-Forwarded-For $proxy_add_x_forwarded_for;
}
#error_page 404 /404.html;
# redirectserver error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location =/50x.html {
root html;
}
}
}
兩臺Apache服務器配置:
安裝 apache + php
安裝php redis擴展
unzip phpredis-master.zip //解壓縮
cd phpredis-master//進入解壓目錄(這一步很重要)
/usr/local/php/bin/phpize//locate phpize,找到phpize(目錄可能不同),並執行生成configture文件
./configure--with-php-config=/usr/local/php/bin/php-config//locate php-config,找到php-config(目錄可能不同),並執行生成php擴展配置文件
make
make test
make install
vi /usr/local/php/etc/php.ini
加入
extension=redis.so
session 共享配置:
修改php.ini文件:vi /usr/local/php/etc/php.ini
session.save_handler =redis
session.save_path = "tcp://192.168.1.6:6379"
session.name = PHPSESSID #redis 數據庫中sessionID的key 鍵名
配置完成!!!重啓nginx 兩臺apache redis 服務器配置允許其他人訪問