环境:(nginx、apache的web服务已经配置好)
NGINX负载服务器:172.28.95.112
NGINX:172.28.95.113
APACHE:172.28.95.115
负载服务器配置:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
[root@LNMP conf]# egrep -v "#|^$" nginx.conf worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; upstream note.t4x.org { server 172.28.95.113:80; #nginx服务器 server 172.28.95.115:80; #Apache服务器 } server{ listen 80; server_name note.t4x.org; location / { proxy_pass http://note.t4x.org; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } } |
测试效果:
0 1 2 3 4 5 6 7 |
[root@lnmp bbs]# echo 172.28.95.113 >index.html #LNMP环境,其中index.html的内容是172.28.95.113 [root@Apache-PHP bbs]# echo "172.28.95.115">index.html #LAP环境,其中index.html内容是172.28.95.115 [root@lnmp bbs]# /usr/local/nginx/sbin/nginx -s stop #关闭LNMP环境的web服务,伪装web服务器宕机 显示效果为:172.28.95.113 [root@lnmp bbs]# /usr/local/nginx/sbin/nginx #启动web [root@Apache-PHP bbs]# /usr/local/apache/bin/apachectl -k stop #关闭apache的web服务 显示效果为:172.28.95.113 当两台服务器都宕机以后显示:502 Bad Gateway |
申明:本文由BYRD原创(基于NGINX、APACHE),未经许可禁止转载! SourceByrd's Weblog-https://note.t4x.org/system/nginx-load-balancing/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!