Centos7 2020 nginx + tomcat8.5部署

环境:yum 装的 nginx

          tar 装的 java 8

          tar 装的 tomcat8.5

         介绍:测试一台服务器跑两个tomcat,由一个nginx代理

 一。 

        环境搭建好之后,先跑tomcat1  :(这里是我装tomcat的地址) /usr/local/tomcat1/bin/startup.sh  (如果用catalins.sh run 方式启动可以看打印日志)     ss -lnpt 查看8080 端口是否启动  ; curl localhost:8080 查看是否有html文件内容返回

         准备tomcat2(因为我这里是同一台服务器跑两个tomcat,需要改些配置)

         cd /usr/local/tomcat2/bin     (我用xftp6软件连接服务器,修改服务器文件内容比较快)

         改 startup.bat  把其中所有CATALINA_HOME替换为CATALINA_HOME1

         改 shutdown.bat  把其中所有CATALINA_HOME替换为CATALINA_HOME2

         改 catalina.bat文件,把其中所有CATALINA_HOME替换为CATALINA_HOME3。

       cd /usr/local/tomcat2/conf 

   修改文件server.xml,修改3个端口号
   ,port改为8015、8025、8035,不冲突即可
   
   将8080改为8081、8082、8083,不冲突即可
   ,portt改为8019、8029、8039,不冲突即可

       /usr/local/tomcat2/bin/startup.sh

    

  二。

      配置nginx 

      vi /etc/nginx/nginx.conf

      这是我的nginx.conf 文件内容

###############################################################

events {
    worker_connections  1024;
}
http {
 
    upstream tomcat {

         #weight权重,默认1,权重越大访问概率越大,backup备用服务器,服务器全部崩溃后启动   
        server localhost:8080 weight=1; 
        server localhost:8081  weight=1; 
        #server localhost:8080 weight=5 backup;
     } 


    #指定服务器的名称和参数     
    server { 
        listen 80;   
        server_name  localhost; 

        #设置字符         
        #charset koi8-r; 

        #location / 指用根目录做负载均衡         
        location / { 
                proxy_pass http://tomcat;   
                proxy_redirect off;
                proxy_set_header Host $host:$server_port;
        proxy_set_header X-Forward-For $remote_addr;       
                proxy_set_header X-Real-IP $remote_addr; 
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        
            } 
    } 
}
#############################################################

然后启动 nginx

systemctl start nginx 

关闭防火墙

本机访问 服务器 ip:80 ,查看是否返回tomcat 页面

     

你可能感兴趣的:(Centos7 2020 nginx + tomcat8.5部署)