0

How can I open my web application in localhost:8080 instead of the tomcat home page For example I want mysite.com:8080/mywebapp to open in mysite.com:8080 Without using any reverse proxy

  • https://stackoverflow.com/questions/7276989/how-to-set-the-context-path-of-a-web-application-in-tomcat-7-0 should still work – Federico klez Culloca May 12 '20 at 13:26
  • But if you want to deploy this on the public internet I suggest you use a reverse proxy instead. – Federico klez Culloca May 12 '20 at 13:27
  • I tried using nginx but it failed the reverse proxy worked but the problem was the css files were not loading at all for example: mysite.com:8080/mywebapp is all good but the same page after reverse proxy (proxy_pass www.mysite.com:8080/mywebapp/) was not loading .min.css files however when I proxy_pass www.mysite.com:8080/ in this case the css files are loading in mysite.com/mywebapp NOTE: mysite is to be replaced by ip address – SOURISH CHANDRAN May 12 '20 at 13:53
  • You can use Httpd as reverse proxy – 0xh3xa May 12 '20 at 13:54
  • @SOURISHCHANDRAN I have added a solution hope this works! – 0xh3xa May 12 '20 at 14:00

1 Answers1

1

You can do this task without any reverse proxy. when you type http://localhost:8080 your website opens

Rename the war file to ROOT.war and put it tomcat webapps directory and restart tomcat

, Or using Reverse proxy

  1. Rename your website to ROOT.war in tomcat webapps directory

  2. Install Httpd

  3. Enable Load mod_proxy_http.so and mod_proxy.so in /etc/httpd/conf/httpd.conf

  4. Add file called example.config under /etc/httpd/conf.d/example.conf And add the following configuration

        <VirtualHost *:8080>
          ServerName exmple.com
          ServerAlias *exmple.com
          ServerAdmin user@gmail.com
          ProxyPreserveHost On
          ProxyRequests off
          AllowEncodedSlashes NoDecode

          <Proxy *>
             Order deny,allow
             Allow from all 
          </Proxy>

          ProxyPass / http://localhost:8080/mywebapp  nocanon
          ProxyPassReverse / http://localhost:8080/mywebapp 

          LogLevel debug
          ErrorLog ${APACHE_LOG_DIR}/error.log
          CustomLog ${APACHE_LOG_DIR}/access.log combined
        </VirtualHost>
0xh3xa
  • 4,801
  • 2
  • 14
  • 28
  • I tried the method you suggest with httpd but now again I am facing the same problem I faced while using nginx – SOURISH CHANDRAN May 13 '20 at 13:42
  • What's the issue you got? I mean you didn't able to reach tomcat or what? – 0xh3xa May 13 '20 at 13:42
  • The .min.css files are not loading while using reverse proxy and in console I am getting "failed to load resources: the server responds with status of 404()" for font-awesome.min.css and bootstrap.min.css – SOURISH CHANDRAN May 13 '20 at 13:45
  • This is strange – 0xh3xa May 13 '20 at 13:45
  • @SOURISHCHANDRAN try this Rename the war file to ROOT.war and put it tomcat webapps directory and restart tomcat – 0xh3xa May 13 '20 at 13:48
  • See for example: the page localhost:8080/mywebapp has a button and all the text are aligned at center where as after reverse proxy localhost/ is loading the page but the button is not there as well as the fonts are not aligned – SOURISH CHANDRAN May 13 '20 at 13:48
  • I think the reverse proxy works fine because it redirects to the request to the tomcat. So I think it's related to the tomcat configuration. The application website uses incorrect paths or application website security. – 0xh3xa May 13 '20 at 13:50
  • Thanks a lot it did work first I didn't understand what root.war was supposed to do so now I know it did work not the way I wanted but it helped thank you again – SOURISH CHANDRAN May 20 '20 at 04:11
  • 1
    And the actual answer for my question how to open mywebapp in localhost:8080 instead of tomcat was to change the war file name to root – SOURISH CHANDRAN May 20 '20 at 04:12
  • You are welcome:) , Glad to hear the issue is solved :) – 0xh3xa May 20 '20 at 12:54