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;
}
}
}