| 
                         fail_timeout,在经历了max_fails次失败后,暂停服务的时间。max_fails可以和fail_timeout一起使用,进行健康状态检查。 
- [root@nginx ~]# vim /etc/nginx/nginx.conf 
 - upstream webservers { 
 - server 192.168.18.201 weight=1 max_fails=2 fail_timeout=2; 
 - server 192.168.18.202 weight=1 max_fails=2 fail_timeout=2; 
 - } 
 
  
10.重新加载一下配置文件 
- [root@nginx ~]# service nginx reload 
 - nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
 - nginx: configuration file /etc/nginx/nginx.conf test is successful 
 - 重新载入 nginx: [确定] 
 
  
重新载入 nginx: [确定] 
11.停止服务器并测试 
先停止Web1,进行测试。 
- [root@web1 ~]# service httpd stop 
 - 停止 httpd: [确定] 
 
  
  
注,大家可以看到,现在只能访问Web2,再重新启动Web1,再次访问一下。 
- [root@web1 ~]# service httpd start 
 - 正在启动 httpd: [确定] 
 
  
  
注,大家可以看到,现在又可以重新访问,说明nginx的健康状态查检配置成功。但大家想一下,如果不幸的是所有服务器都不能提供服务了怎么办,用户打开页面就会出现出错页面,那么会带来用户体验的降低,所以我们能不能像配置LVS是配置sorry_server呢,答案是可以的,但这里不是配置sorry_server而是配置backup。 
12.配置backup服务器 
- [root@nginx ~]# vim /etc/nginx/nginx.conf 
 - server { 
 - listen 8080; 
 - server_name localhost; 
 - root /data/www/errorpage; 
 - index index.html; 
 - } 
 - upstream webservers { 
 - server 192.168.18.201 weight=1 max_fails=2 fail_timeout=2; 
 - server 192.168.18.202 weight=1 max_fails=2 fail_timeout=2; 
 - server 127.0.0.1:8080 backup; 
 - } 
 - [root@nginx ~]# mkdir -pv /data/www/errorpage 
 - [root@nginx errorpage]# cat index.html 
 - <h1>Sorry......</h1> 
 
  
13.重新加载配置文件 
- [root@nginx errorpage]# service nginx reload 
 - nginx: the configuration file /etc/nginx/nginx.conf syntax is ok 
 - nginx: configuration file /etc/nginx/nginx.conf test is successful 
 - 重新载入 nginx: [确定] 
 
  
14.关闭Web服务器并进行测试 
- [root@web1 ~]# service httpd stop 
 - 停止 httpd: [确定] 
 - [root@web2 ~]# service httpd stop 
 - 停止 httpd: [确定] 
 
  
  
注,大家可以看到,当所有服务器都不能工作时,就会启动备份服务器。好了,backup服务器就配置到这里,下面我们来配置ip_hash负载均衡。 
15.配置ip_hash负载均衡                         (编辑:泰州站长网) 
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! 
                     |