首先创建tomcat的文件夹,为了方便docker的配置我这里直接在根目录中创建第一步:创建文件夹:发布文件夹
mkdir-p/docker/tomcat/webapp8081
mkdir-p/docker/tomcat/webapp8082
mkdir-p/docker/tomcat/webapp8083
第二步:创建tomcat容器(端口可以根据自己的实际更换)
dockerrun-d--nametomcat8081-p8081:8080-v/docker/tomcat/webapp8081:/usr/local/tomcat/webapps/tomcat
dockerrun-d--nametomcat8082-p8082:8080-v/docker/tomcat/webapp8082:/usr/local/tomcat/webapps/tomcat
dockerrun-d--nametomcat8083-p8083:8080-v/docker/tomcat/webapp8083:/usr/local/tomcat/webapps/tomcat
创建完成后使用dockerps命令进行查看是否创建成功并且使用
第三步:查看tomcat的ip使用命令依次查询这里只使用第一个举例
第四步:为了方便测试我这里就不上传war包了,直接在里面创建了一个hello/index.html文件
注意:如果nginx为docker容器,必须使用tomact容器ip,否则连不上
首先在官网上下载nginx的官方版本
点击右边导航栏的download,进入下载界面选择对应的版本进行下载,我这里就使用nginx-1.6.2.tar
下载完成后,将文件放到自定义的文件夹,我这里放到/usr/local/tools/nginx-1.6.2
使用这个命令将nginx解压:
解压完成后,我这里是返回根目录,在根目录创建一个宿主文件夹,目的是为了创建文件,使得nginx可以挂载(你也可以自定义)
vim/docker/nginx/nginx.conf
mkdir-p/docker/nginx/html
拷贝页面你解压的negix中的html文件夹中的index.html50x.html到/docker/nginx/html文件夹中
这里提供一种negix的conf文件,以为加上注解所以格式可能会发生改变记得把注解删了
worker_processes2;error_loglogs/error.log;
#error_loglogs/error.lognotice;
#error_loglogs/error.loginfo;
worker_connections1024;#最大连接数量
default_typeapplication/octet-stream;
server172.17.0.3:8080weight=10;
#另外mytomcat这里名字和下方的名字保持一致这里需要和你的tomcatip保持一致
server172.17.0.4:8080weight=50;
server172.17.0.5:8080weight=10;

#'$status$body_bytes_sent"$http_referer"'
#'"$http_user_agent""$http_x_forwarded_for"';
#access_loglogs/access.logmain;
#access_loglogs/host.access.logmain;
#indexindex.htmlindex.htm;
proxy_passhttp://mytomcat;
#redirectservererrorpagestothestaticpage/50x.html
error_page500502503504/50x.html;
#proxythephpscriptstoapachelisteningon127.0.0.1:80
#proxy_passhttp://127.0.0.1;
#passthephpscriptstofastcgiserverlisteningon127.0.0.1:9000
#fastcgi_pass127.0.0.1:9000;
#fastcgi_paramscript_filename/scripts$fastcgi_script_name;
#denyaccessto.htaccessfiles,ifapache'sdocumentroot
#anothervirtualhostusingmixofip-,name-,andport-basedconfiguration
#server_namesomenamealiasanother.alias;
#indexindex.htmlindex.htm;
#ssl_certificatecert.pem;
#ssl_certificate_keycert.key;
#ssl_session_cacheshared:ssl:1m;
#ssl_ciphershigh:!anull:!md5;
#ssl_prefer_server_cipherson;
#indexindex.htmlindex.htm;
}
使用docker启动
81:是外网访问的端口这里可以根据实际做修改
/docker/nginx/nginx.conf本地的宿主文件
/etc/nginx/nginx.conf解压的目录(也可以不更改)
/docker/nginx/html本地的宿主文件
/usr/share/nginx/html解压的目录
dockerrun-d--namenginx81-p81:80-v/docker/nginx/nginx.conf:/etc/nginx/nginx.conf-v/docker/nginx/html:/usr/share/nginx/htmlnginx
测试
以上就是Docker怎么使用nginx搭建tomcat集群的详细内容,更多请关注主机测评网其它相关文章!
本文来源:国外服务器--Docker怎么使用nginx搭建tomcat集群(dockernginxkeepalived)
本文地址:https://www.idcbaba.com/guowai/2438.html
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 1919100645@qq.com 举报,一经查实,本站将立刻删除。