nginx反向代理tomcat多实例

1.tomcat多实例配置_基于端口号

前期需要准备java 环境 这里不作赘述

bash 复制代码
# 下载tomcat源码包
# 清华站点下载
https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.5.95/bin/apache-tomcat-8.5.95.tar.gz
https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-9/v9.0.82/bin/apache-tomcat-9.0.82.tar.gz
https://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-10/v10.1.15/bin/apache-tomcat-10.1.15.tar.gz


[root@localhost tar]# tar xf apache-tomcat-8.5.96.tar.gz 
[root@localhost tar]# ls
apache-tomcat-10.1.24.tar.gz  apache-tomcat-8.5.96.tar.gz       jdk-8u251-linux-x64.tar.gz  jvmtop-0.8.0.tar.gz
apache-tomcat-8.5.96          jdk-11.0.23_linux-x64_bin.tar.gz  jpress-web-newest.war       visualvm_202.zip

[root@localhost tar]# cp -a apache-tomcat-8.5.96 /usr/local/tomcat8.5_01
[root@localhost tar]# cp -a apache-tomcat-8.5.96 /usr/local/tomcat8.5_02

[root@localhost tar]# ll /usr/local/ | grep tomcat
drwxr-xr-x. 9 root root 220 9月  23 11:39 tomcat8.5_01
drwxr-xr-x. 9 root root 220 9月  23 11:39 tomcat8.5_02

[root@localhost tar]# sed -i 's#8005#8011#;s#8080#8081#' /usr/local/tomcat8.5_01/conf/server.xml
[root@localhost tar]# sed -i 's#8005#8012#;s#8080#8082#' /usr/local/tomcat8.5_02/conf/server.xml

[root@localhost tar]# /usr/local/tomcat8.5_01/bin/startup.sh 
[root@localhost tar]# /usr/local/tomcat8.5_02/bin/startup.sh

[root@localhost tar]# ss -tuln | grep 80                                         
tcp    LISTEN     0      100      :::8081                 :::*                  
tcp    LISTEN     0      100      :::8082                 :::*  

2.nginx 反向代理tomcat

bash 复制代码
# 安装
[root@localhost tar]# yum -y install nginx

[root@localhost tar]# systemctl start nginx

[root@localhost tar]# netstat -lntup | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      29873/nginx: master 
tcp6       0      0 :::80                   :::*                    LISTEN      29873/nginx: master 

[root@localhost tar]# vim /etc/nginx/conf.d/tomcat.conf 

 upstream tomcatWeb {
        server 192.168.29.200:8081;
        server 192.168.29.200:8082;
    }

    server {
        listen       80;
        server_name  192.168.29.200;
        location / {
            proxy_pass http://tomcatWeb;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

[root@localhost tar]# echo 8081 > /usr/local/tomcat8.5_01/webapps/ROOT/index.jsp 
[root@localhost tar]# echo 8082 > /usr/local/tomcat8.5_02/webapps/ROOT/index.jsp
[root@localhost tar]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@localhost tar]# systemctl restart nginx

[root@localhost tar]# curl 192.168.29.200
8081
[root@localhost tar]# curl 192.168.29.200
8081
[root@localhost tar]# curl 192.168.29.200
8082
[root@localhost tar]# curl 192.168.29.200
8082
[root@localhost tar]# curl 192.168.29.200
8081
相关推荐
likfishdn14 分钟前
Linux的文件与目录管理
linux·运维·服务器
chian-ocean34 分钟前
Linux 文件缓冲区:高效数据访问的幕后推手
linux·运维·服务器
加油=^_^=36 分钟前
【Linux】进程优先级 | 进程调度(三)
linux·运维·服务器
若云止水1 小时前
Ubuntu 下 nginx-1.24.0 源码分析 - ngx_init_cycle 函数 - 详解(4)
数据库·nginx·ubuntu
元气满满的热码式1 小时前
Docker数据卷操作实战
linux·运维·docker·云原生·容器
北京耐用通信1 小时前
航空装配自动化神器Ethercat转profient网关搭配机器人精准控制
运维·机器人·自动化
吃汤圆的抹香鲸2 小时前
Rider 安装包 绿色版 Win/Mac/Linux 适合.NET和游戏开发者使用 2025全栈开发终极指南:从零配置到企业级实战
linux·运维·windows·sql·游戏·macos·.net
崔lc4 小时前
linux中安装部署Jenkins,成功构建springboot项目详细教程
运维·jenkins
浪九天4 小时前
Nginx系列05(负载均衡、动静分离)
nginx·运维开发·持续部署
luojiaao4 小时前
【Jenkins】个人向-Jenkinsfile如何写
运维·jenkins