Docker Nginx 负载均衡配置

nginx容器启动命令:

docker run --name nginx89 -d -p 89:80 -v /data/nginx/html:/usr/share/nginx/html -v /data/nginx/conf/nginx.conf:/etc/nginx/nginx.conf  -v /data/nginx/logs:/var/log/nginx -v /data/nginx/conf.d:/etc/nginx/conf.d -d nginx

修改了配置,重启容器命令:

docker container restart nginx89 

配置nginx宿主机使用目录,将nginx使用的配置文件,和日志输出到宿主机

[root@localhost nginx]# pwd
/data/nginx
[root@localhost nginx]# ll
总用量 0
drwxr-xr-x. 2 root root 24 3月  27 23:13 conf
drwxr-xr-x. 2 root root 26 3月  27 23:25 conf.d
drwxr-xr-x. 2 root root  6 3月  27 17:43 html
drwxr-xr-x. 2 root root 41 3月  27 22:31 logs
[root@localhost nginx]#

在conf目录下面,建立nginx入口配置文件nginx.conf,配置内容如下



    upstream pic {
        server 172.17.0.2:8080;
        server 172.17.0.3:8080;
    }

    include /etc/nginx/conf.d/*.conf; 


在conf.d目录下面建立各个模块的配置文件 ,内容如下: 

server{
        listen  80;
        server_name localhost ;
        location / {
                proxy_set_header X-Real-IP $remote_addr;
                proxy_set_header X-Forward-For $proxy_add_x_forwarded_for;
                proxy_set_header Host $http_host;
                proxy_set_header X-Nginx-Proxy true;
                proxy_pass http://pic;
                proxy_redirect off;
        } 

}


在宿主机上面,启动了两个容器,容器中是对应的Tomcat服务 ,容器启动之后有自己对应的ip,可以使用对应的ip访问服务 

分别为:172.17.0.2:8080,172.17.0.3:8080 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

半山猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值