采用ubuntu系统,docker安装自行百度

1.安装tomcat

docker run -d -p : tomcat
docker run -d -p : tomcat

安装两个实例,端口分别为8088,8089

2.安装nginx

docker run -p : -d docker.io/nginx

安装nginx,端口为8080。在测试的过程中,发现ubuntu上对80端口有限制,不能直接访问,所以映射为8080

3.修改nginx配置

3.1查看实例

    sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
516b1562b0e3 nginx "nginx -g 'daemon of…" minutes ago Up minutes 0.0.0.0:->/tcp musing_dewdney
36e48585253f tomcat "catalina.sh run" About an hour ago Up About an hour 0.0.0.0:->/tcp keen_wescoff
7eb77e6a33e5 tomcat "catalina.sh run" About an hour ago Up About an hour 0.0.0.0:->/tcp frosty_grothendieck
2069f54ea331 mysql:5.7 "docker-entrypoint.s…" hours ago Up hours 0.0.0.0:->/tcp, /tcp mysqltest

3.2进入nginx的bash

sudo docker exec -it 516b1562b0e3 bash

3.3修改配置

#user  nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} http {
include mime.types;
default_type application/octet-stream; proxy_buffer_size 128k;
proxy_buffers 128k;
proxy_busy_buffers_size 128k; sendfile on;
#tcp_nopush on; #keepalive_timeout ;
keepalive_timeout ; #gzip on; # 注意,这里的server名字即org.tonny.balance不能带下划线,tomcat是上面安装的tomcat
upstream org.tonny.balance {
server 192.168.126.128: weight=;
server 192.168.126.128: weight=;
} server {
#注意,这里保留80,因为前面的docker运行命令,会映射80端口
listen ;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; # 不带数据的请求
location / {
root html;
index index.html index.htm;
#访问映射
proxy_pass http://org.tonny.balance;
} #error_page /.html; # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root html;
}
}
}

3.4重启nginx

sudo docker restart 516b1562b0e3

4.测试

通过ip,端口访问即可

docker上配置nginx负载均衡的更多相关文章

  1. docker容器配置nginx负载均衡 -----加权

    首先要准备三个nginx的容器: 第二个容器: 第三个容器: 进入第一个容器  要配置的容器(docker exec -it 容器名 /bin/bash) vi /usr/local/nginx/co ...

  2. 利用Docker快速创建Nginx负载均衡节点

    本文版权归博客园和作者吴双本人共同所有 转载和爬虫请注明原文地址 www.cnblogs.com/tdws 一.Self-Host Kestrel 1. 在vs2017中新建dotnet core2. ...

  3. 配置nginx负载均衡

    配置nginx负载均衡 执行命令:vi /usr/local/nginx/sbin/nginx/conf/nginx.conf 修改为: worker_processes  2; events {   ...

  4. Linux配置Nginx负载均衡

    nginx配置负载均衡其实很简单,一直还以为负载均衡是个很高端人士玩的 首先先了解下负载均衡,假设一个场景,如果有1000个客户同时访问你服务器时,而你只有一台服务器的Nginx,且只有一个MySQL ...

  5. 如何配置nginx负载均衡配置(轮询,权重,ip绑定)

    集群是为了解决单节点无法服务高并发的情况,在集群中nginx是如何分配将来自客户端的请求 转发给服务器的 负载均衡可以提高网站的吞吐量(接受和响应),减轻单台服务器的压力 负载均衡提供了三种策略:轮询 ...

  6. linux下配置nginx负载均衡例子

    准备2台虚拟机: 分别在两个虚拟机上安装tomcat,并在服务器A安装nginx,其中nginx端口设置为了 70. 服务器A的tomcat安装目录: 服务器B的tomcat安装目录: 服务器A的ng ...

  7. 三、netcore跨平台之 Linux配置nginx负载均衡

    前面两章讲了netcore在linux上部署以及配置nginx,并让nginx代理webapi. 这一章主要讲如何配置负载均衡,有些步骤在前两章讲的很详细了,所以这一章我就不会一个个截图了. 因为本人 ...

  8. Mac下配置Nginx负载均衡

    1.首先在Mac下安装Nginx(可参考我的另一篇随笔http://www.cnblogs.com/malcolmfeng/p/6896703.html). 2.安装Tomcat,下载后,解压,bin ...

  9. docker Dockerfile学习---nginx负载均衡tomcat服务

    1.此过程在nginx的基础上,也就是上篇博客写的内容. 2.创建项目目录并上传包,解压 $ mkdir centos_tomcat $ cd centos_tomcat $ tar zxvf jdk ...

随机推荐

  1. codeforces 691D D. Swaps in Permutation(dfs)

    题目链接: D. Swaps in Permutation time limit per test 5 seconds memory limit per test 256 megabytes inpu ...

  2. php连接数据库步骤

    第一步:连接数据库 $link=@mysql_connect('localhost','root','root') or die('数据库连接失败!'); echo '连接成功!'; 这里数据库连接函 ...

  3. Watir: Watir-WebDriver对富文本编辑器的定位于Watir是不一致的。

    Watir对富文本编辑,一般可以采用b.frame().document.body.innerText = "Value you want to insert"但是Watir-We ...

  4. fastText(三):微博短文本下fastText的应用(二)

    上一篇讲到,fastText在训练数据中过拟合的问题.接下来将介绍一些提高fastText泛化能力的尝试. 模型泛化使用过fastText的人,往往会被它的很多特性征服,例如训练速度.兼具word e ...

  5. 通过链接将JSP页面中一变量传到另一JSP界面中

    A.jsp 发送 <a herf="B.jsp?name=<%=name%>">传递到B页面</a> B.jsp  接收 <%String ...

  6. File System Programming---(三)

    Accessing Files and Directories Before you can open a file, you first have to locate it in the file ...

  7. bzoj 4316: 小C的独立集【仙人掌dp】

    参考:https://www.cnblogs.com/clrs97/p/7518696.html 其实和圆方树没什么关系 设f[i][j][k]为i点选/不选,这个环的底选不选 这个底的定义是设u为这 ...

  8. IT兄弟连 JavaWeb教程 ServletContext对象

    ServletContext是Servlet与Servlet容器之间直接通信的接口.Servlet容器在启动一个Web应用时,会为它创建一个ServletContext对象.每个Web应用都有唯一的S ...

  9. GitHub笔记---邮箱访问错误

    GitHub地址太长,所以需要一个变量来保存 把远程仓库赋值给一个变量,以后就用就这变量代表这个地址 GitHub推送push 推送过程中发生一个小插曲,出现了错误,错误提示我复制过来吧 remote ...

  10. elasticsearch接口开发(新)

    此文在上一篇文章的基础上稍做了些许修改,主要在springboot整合ES后的包路径上,如下是新的目录结构 下面贴出代码 MyConfig.java package com.ylht.config; ...