docker nginx 负载均衡
index1.html
<html>
<head>
<title>lb-test</title>
</head>
<body>
<p>11111111</p>
</body>
</html>
同理建立index2.html,内容为222222
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
upstream yourwebname {
# yourhostip:port;
server 192.168.43.130:8000 weight=2;
server 192.168.43.130:8001 weight=2;
}
server {
listen 80;
location / {
proxy_pass http://yourwebname;
}
}
}
启动镜像
run -p 80:80 -v /home/nginx.conf:/etc/nginx/nginx.conf --name master nginx
docker run -p 8000:80 --name myweb1 -v /home/index1.html:/usr/share/nginx/html/index.html -d nginx
docker run -p 8001:80 --name myweb2 -v /home/index2.html:/usr/share/nginx/html/index.html -d nginx
浏览器访问192.168.43.130,持续刷新即可看到1111111,22222222内容交替显示