docker ngnix + tomcat 安装

参考:https://www.cnblogs.com/lichmama/p/11366262.html
1
mkdir -p ./nginx/www ./nginx/conf/ ./nginx/logs
mkdir -p ./tomcat/webapps/ROOT ./tomcat/conf ~/tomcat/logs

2
在tomcat/webapps/ROOT中创建index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>docker deployment</title>
</head>
<body>
<h1>hello, world</h1>
<img src="/static/image/lichmama.png">
</body>
</html>

3 .运行tomcat

docker run -d --name tomcat1 -v /home/tomcat/webapps:/usr/local/tomcat/webapps tomcat
docker run -d --name tomcat2 -v /home/tomcat/webapps:/usr/local/tomcat/webapps tomcat

4. 读取tomcat ip ,加入 nginx
docker inspect tomcat1|grep "IPAddress"
docker inspect tomcat2|grep "IPAddress"

5. ngnix 增加
在nginx/conf增加配置文件nginx.conf:
user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;


events {
worker_connections 1024;
}


http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for" "$upstream_addr"';

access_log /var/log/nginx/access.log main;

sendfile on;
#tcp_nopush on;

keepalive_timeout 65;

#gzip on;

upstream tomcat {
server 172.17.0.2:8080;
server 172.17.0.4:8080;
}

server {
listen 80;
server_name localhost;

location / {
proxy_pass http://tomcat;
proxy_redirect off;
index index.html index.htm;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Real-Port $remote_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

location /static/ {
alias /usr/share/nginx/html/;
}
}

include /etc/nginx/conf.d/*.conf;
}


5.启动nginix
docker run -d -p 80:80 --name nginx -v /home/nginx/www:/usr/share/nginx/html -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/logs:/var/log/nginx nginx

posted @ 2021-03-15 16:48  InvApp  阅读(52)  评论(0编辑  收藏  举报