docker-compose.yml 部署Nginx、Java项目、MySQL、Redis

docker-compose.yml 部署Nginx、Java项目、MySQL、Redis

root@andre:/usr/local/docker/nginx# vim docker-compose.yml 

version: '3.7'
services:
  nginx:
    image: nginx
    restart: always
    container_name: nginx
    ports:
      - "81:80"
      - "443:443"
      - "9000:9000"
    volumes:
      - ./conf/nginx.conf:/etc/nginx/nginx.conf
      - ./wwwroot:/usr/share/nginx/wwwroot
~                                          

启动之前先配置nginx.conf

root@andre:/usr/local/docker/nginx/conf# vim nginx.conf 

user nginx;
worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  192.168.100.7;

        location / {
            root   /usr/share/nginx/wwwroot/html81;
            index  index.html index.htm;
        }
    }

    server {
        listen       9000;
        server_name  192.168.100.7;

        location / {
            root   /usr/share/nginx/wwwroot/html9000;
            index  index.html index.htm;
        }
    }
}

在配置对应的nginx.conf里面需要的 html文档

root@andre:/usr/local/docker/nginx/wwwroot/html81# cat index.html 
hello nginx

反向代理tomcat

加上proxy_pass http://192.168.100.7:9090;之后,监听80端口就会给到tomcat 9090服务器,又会被docker-compose映射成81端口访问。

root@andre:/usr/local/docker# vim docker-compose.yml 

version: '3.7'
services:
  tomcat1:
    image: tomcat
    restart: always
    container_name: tomcat1
    ports:
      - "9090:8080"

  tomcat2:
    image: tomcat
    restart: always
    container_name: tomcat2
    ports:
      - "9091:8080"

root@d79a28846537:/usr/local/tomcat/webapps/ROOT# echo "9090" > index.html
root@d79a28846537:/usr/local/tomcat/webapps/ROOT# ls
index.html
root@6de1fdafc0d9:/usr/local/tomcat/webapps/ROOT# ls
index.html
root@6de1fdafc0d9:/usr/local/tomcat/webapps/ROOT# cat index.html 
9091
root@andre:/usr/local/docker/nginx/conf# vim nginx.conf 

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  192.168.100.7;

        location / {
            proxy_pass http://192.168.100.7:9090;
            index  index.html index.htm;
        }
    }

    server {
        listen       9000;
        server_name  192.168.100.7;

        location / {
            root   /usr/share/nginx/wwwroot/html9000;
            index  index.html index.htm;
        }
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值