Docker Compose 部署Nginx反向代理 tomcat

Nginx 、Tomcat (默认端口8080)》》compose

csharp 复制代码
services:
  nginx:
    image: nginx:latest
    container_name: nginx
    restart: always
    ports:
      - 80:80
      - 8080:8080
    volumes:
      # 文件夹会自动创建,但nginx.conf是文件,需要提前创建,否则 会自动创建nginx.conf文件夹
      - ./conf/nginx.conf:/etc/nginx/nginx.conf
      - ./html:/usr/share/nginx/html
  tomcat1:
    image: tomcat:latest
    container_name: tomcat1

  tomcate2:
    image: tomcat:latest
    container_name: tomcat2

nginx的配置文件

csharp 复制代码
worker_processes  2;

events {
    worker_connections  1024;
}

http {
   upstream httpd {
        server tomcat1:8080 weight=10;
        server tomcat2:8080 weight=10;
   }
   include       mime.types;
   default_type  application/octet-stream;

   sendfile        on;

   server {
       listen       80;
       #  为了模拟域名访问,  需要在访问的客户端 host 加   IP  service.zen.com
       server_name  service.zen.com;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
          proxy_pass http://httpd;
        }

    }

}

运行 compose

csharp 复制代码
#  运行 compose
docker compose up -d

# 查看运行的容器进程
docker ps

# 因tomcat 拉取 阿里云的, 阿里云是处理过的 ,保留核心的内容了
# 进入tomcat 容器
docker exec -it tomcat容器ID   /bin/bash
# 阿里云拉取的 tomcat   /usr/local/tomcat/webapps  是空的 阿里云把内容 存在 webapps.dist文件夹里了
cp -r  webapps.dist/* webapps/


相关推荐
杨浦老苏13 分钟前
IMAP电子邮件归档系统Mail-Archiver
docker·群晖·邮件·email
超级小忍4 小时前
深入解析 Apache Tomcat 配置文件
java·tomcat·apache
jzy37115 小时前
主机管理优化方案:安全加固、资源整合与跨团队协作
linux·tomcat
KS、zheng6 小时前
【DOCKER】Windows Server 2016 Datacenter离线安装Docker引擎
windows·docker·容器
企鹅侠客11 小时前
2 安装 Docker 和 Jenkins:持续构建环境起步
docker·容器·jenkins·持续构建环境部署
亲爱的非洲野猪11 小时前
Nginx vs Spring Cloud Gateway:限流功能深度对比与实践指南
运维·nginx
石小千12 小时前
Nginx服务做负载均衡网关
运维·nginx·负载均衡
liweiweili12615 小时前
Tomcat 服务器日志
java·运维·服务器·tomcat
gs801401 天前
GitLab Docker Compose 迁移后 Redis 权限问题排查与解决
redis·docker·gitlab