Docker 安装tomcat:7 挂载目录到本地_Aaかzjs的博客-CSDN博客
docker run -d --name tomcat-test -p 8080:8080 --privileged=true --restart always -v /opt/tomcat/webapps/:/usr/local/tomcat/webapps -v /opt/tomcat/logs/:/usr/local/tomcat/logs tomcat:7
测试访问tomcat IP+端口
创建nginx 容器 不懂可以参考链接
Docker挂载nginx到本地目录_Aaかzjs的博客-CSDN博客
创建nginx 容器并且挂载到本地
docker run -d --name nginx -p 80:80 -v /opt/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /opt/nginx/conf.d:/etc/nginx/conf.d -v /opt/nginx/logs/:/var/log/nginx -v /opt/nginx/html:/usr/share/nginx/html nginx:latest
测试访问nginx IP+端口
Nginx 挂载目录/opt/nginx/ (最好看上两篇文章,是连载的,一起做下来)
我们已经挂载好nginx在本地,所以可以直接进入挂载目录修改nginx.conf配置文件
cd /opt/nginx/
ls
cd conf
ls
看到配置文件niginx.conf
vim nginx.conf
轮询方式配置
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
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"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
upstream tomcat {
server 192.168.61.134:8080;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://192.168.61.134:8080;
index index.html index.htm;
}
}
include /etc/nginx/conf.d/*.conf;
}
或者添加,上面用的轮询方式,这个静态配置
server {
listen 80;
server_name localhost;
location / {
root html;
proxy_pass http://192.168.61.134:8080;
index index.html index.htm;
}
}
重新启动nginx
docker restart nginx
docker ps
测试访问192.168.61.134实现跳转到tomcat
成功代理tomcat