Search code examples
javatomcatwebserver

how to install multiple version of tomcat on single machine binded in port 80?


I have three web app running on three version of tomcat like this:

  1. app1 work on tomcat 7 and jdk 7 (app1domain.com:2121)
  2. app2 work on tomcat 8 and jdk 8 (app2domain.com:2222)
  3. app3 work on tomcat 9 and jdk 8 (app3domain.com:2323)

There is windows server 2012. I want to use port 80 for all tomcat above and user can see app1domain.com without port number

I can install other tomcat and I want use virtual hosting for every tomcat

Is there any software or solution to do that ?


Solution

  • Use nginx, easy to use and free as proxy software to manage apps and web servers. First you can config tomcats,In tomcat server.xml

    <!-- Tomcat listen on 8080 -->
    <Connector port="8080" protocol="HTTP/1.1"
       connectionTimeout="20000"
       URIEncoding="UTF-8"
       redirectPort="8443" />
    <!-- dont change the code up -->
    <!-- Set /apple as default path -->
    <Host name="localhost"  appBase="webapps"
         unpackWARs="true" autoDeploy="true">
    
     <Context path="" docBase="apple">
         <!-- Default set of monitored resources -->
         <WatchedResource>WEB-INF/web.xml</WatchedResource>
     </Context>
    </Host>
    

    In Nginx, edit /etc/nginx/sites-enabled/default, put following content : /etc/nginx/sites-enabled/default

    server {
      listen          80;
      server_name     yourdomain.com;
      root            /etc/tomcat7/webapps/apple;
    
      proxy_cache one;
    
      location / {
            proxy_set_header X-Forwarded-Host $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://127.0.0.1:8080/;
      }
    }
    

    It tells Nginx to redirect the traffics from port 80 to Apache Tomcat on port 8080. Done, restart Nginx.

    source link