编辑文件nginx.conf添加
[root@server1 conf]# vim nginx.conf
http {
13 include mime.types;
14 default_type application/octet-stream;
15 upstream westos{
16 server 172.25.254.3:80;
17 }
server {
48
49 listen 80;
50 server_name www.westos.org;
51 location / {
52 proxy_pass http://westos;
53 }
54 }
测试
[root@server1 conf]# nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
同时在真机中/etc/hosts
要写上解析172.25.254.1 www.westos.org westos.org
打开辅助虚拟机server3和server2同时打开hpptd服务
在真机上进行测试
当在upstream中添加
server 172.25.254.2:80;即可实现负载均衡
利用ip_hash;实现同一个ip地址只调用一个ip后端
upstream westos{
server 172.25.254.3:80;
server 172.25.254.1:80 backup
}
让server1作为后端,关闭server3http服务此时测试可得
来源:CSDN
作者:silence-1
链接:https://blog.csdn.net/qq_41871875/article/details/104511885