这是Web集群。
这是Web集群中的135。
Window客户端可以直接通过IP地址的方式对Web服务器(192.168.168.135)进行访问: http://192.168.168.135/ ###### 第二台Web服务器(192.168.168.154),使用了基于域名的虚拟主机discuz.zhuohua.store: 网站的首页文件的内容:(index.html)这是Web集群。
这是Web集群中的154。
Window客户端访问Web服务器(192.168.168.154)的基于域名的虚拟主机:(在没有DNS服务器解析域名的情况下,可以在文件hosts里绑定) http://discuz.zhuohua.store/ ########## 配置Nginx服务器,修改Nginx的主配置文件: [root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf 修改为:( 必须要在 http {} 里面 ) upstream webservers_1{ ip_hash; server 192.168.168.135:80 weight=1 max_fails=2 fail_timeout=2; server 192.168.168.154:80 weight=1 max_fails=2 fail_timeout=2; } server { listen 80; #Nginx的端口 server_name discuz.zhuohua.store; location / { proxy_pass http://webservers_1; proxy_set_header Host $http_host; } } 如下图: 注释:此时,外面的客户端访问Nginx服务器的域名 discuz.zhuohua.store的TCP 80端口时,等于访问192.168.168.135或192.168.168.154的TCP 80端口。 重启Nginx服务,使更改生效: [root@localhost ~]# service nginx restart [root@localhost ~]# Window客户端重新把域名解析到Nginx服务器的IP地址: 假如客户端被自动分配到Web服务器(192.168.168.154)后,就会一直停留在Web服务器(192.168.168.154): ### 当Web服务器(192.168.168.154)停止了Web服务后,客户就会自动跳到Web服务器(192.168.168.135),在这过程中,没有出现访问失败的迹象: ### 当Web服务器(192.168.168.154)恢复正常后,客户端会自动跳回Web服务器(192.168.168.154): 笺注:实际生产环境中,集群里的所有Web服务器的网页内容应该是一样的。 相关文章: CentOS6_Nginx反向代理+基于域名的虚拟主机 CentOS6_Nginx反向代理+负载均衡(ip_hash)欢迎光临 blog.zhuohua.store (http://blog.zhuohua.store/) | Powered by Discuz! 7.2 |