登录
    Technology changes quickly but people's minds change slowly.

docker 下nginx 负载均衡配置

技术宅 破玉 1762次浏览 0个评论

获取nginx镜像

docker pull nginx

编写nginx配置文件

hello.conf,这里方便搞成一个文件,多个站点最好拆分成多个,这里配置两个站点的负载均衡

upstream hello { 
    server 192.168.0.108:8888;
    server 192.168.0.108:8889;
}
server {
    listen       8899;
    server_name  localhost;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        proxy_set_header Host $host;
        proxy_pass http://hello;

    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}
upstream haha { 
    server 192.168.0.108:8888;
    server 192.168.0.108:8889;
}
server {
    listen       8877;
    server_name  localhost;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
        proxy_set_header Host $host;
        proxy_pass http://haha;

    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

}

运行nginx 容器

我们需要将端口映射出来

docker  run -d --name nginx-gate -p 8899:8001 -p 8877:8002  nginx

拷贝 配置文件到容器内,或者直接将配置文件夹映射到磁盘

docker cp hello.conf nginx-gate:/etc/nginx/conf.d/

重启容器:

docker restart nginx-gate

华裳绕指柔, 版权所有丨如未注明 , 均为原创|转载请注明docker 下nginx 负载均衡配置
喜欢 (1)
发表我的评论
取消评论
表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址