• 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内容交替显示
    app1
    app2

  • 相关阅读:
    scapy--初识
    python--re(匹配字符串)
    python--pdb
    Fedora 配置
    Ubuntu 18.04 配置
    python--git
    python--os
    day28 Pyhton 面向对象 继承
    day28 Pyhton MRO和C3算法
    数学知识回顾02
  • 原文地址:https://www.cnblogs.com/vickey-wu/p/8873994.html
Copyright © 2020-2023  润新知