栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Docker 挂载nginx 实现nginx反向代理tomcat

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Docker 挂载nginx 实现nginx反向代理tomcat

Docker 搭建tomcat挂载本地、搭建nginx 挂载本地、实现nginx反向代理tomcat三篇文章是连载的,不懂的可以一起看,超级详细。

创建tomcat 容器,不懂可以参考链接

Docker 安装tomcat:7 挂载目录到本地_Aaかzjs的博客-CSDN博客

创建tomcat 容器并且挂载到本地
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 反向代理

Nginx 挂载目录/opt/nginx/ (最好看上两篇文章,是连载的,一起做下来)

我们已经挂载好nginx在本地,所以可以直接进入挂载目录修改nginx.conf配置文件

cd /opt/nginx/
ls
cd conf
ls

看到配置文件niginx.conf

 

 修改nginx.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

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/841531.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号