Tomcat Webapp on port 80

37,963

Solution 1

There are several ways to achieve this, but the most common way to solve it is to run Apache as a reverse proxy in front of it. You can find some details here. This will work on both Linux and Windows. For Linux, you can also use authbind to allow Tomcat to bind to port 80. Just changing the port to 80 in your server.xml will not work in Linux, since it would require you to start Tomcat as root, which is not a very good idea.

Also, to have your webapp at /, you can deploy your war file as ROOT.war.

Solution 2

Running any application on a privileged port (those below 1024) requires special privileges. If you do this, you should ensure your instance is properly hardened.

To configure the port tomcat listens on you have to modify the HTTP connector in conf/server.xml (server reference documentation):

<Connector port="80" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />

To change the context path of an app, you can rename the war file. To deploy it at the root, rename your war file to ROOT.war. Or you can add a META-INF/context.xml in which you can specify the desired context path (context reference docs):

<?xml version="1.0" encoding="UTF-8"?>
<Context path="/" />

Solution 3

You need to set apache webserver and configure it to use tomcat.

You need to use mod_jk in order to configure apache webserver to communicate with tomcat.

Use this link to set up the mod_jk.

Share:
37,963
eLRuLL
Author by

eLRuLL

Making a better future for Peruvian coders. linkedin github twitter hackhands For a more direct help: Winter Bash: 2017: 1st place on StackOverflow 2018: 1st place on StackExchange

Updated on May 02, 2020

Comments

  • eLRuLL
    eLRuLL about 4 years

    I have a webapp on my tomcat server like this:

    mydomain.com:8080/mywebapp

    Then I connect to my webapp, and it is working correctly, but what I want is to see my webapp like this:

    mydomain.com

    So I don't want only tomcat on port 80, I don't want to access my webapp through its name, I want to connect directly using my domain URI.

    How can I do this? I want this to work with Linux (Ubuntu 12.04 LTS) and Windows servers.

  • eLRuLL
    eLRuLL about 11 years
    Great, I think I'll use authbind, using these steps: java.dzone.com/articles/running-tomcat-port-80-user
  • eLRuLL
    eLRuLL about 11 years
    I already tried the change port to 80 thing, but it doesn't work on linux, maybe it needs some additional steps, but I don't want security risks.
  • ilikeorangutans
    ilikeorangutans about 11 years
    That's probably because tomcat is not running as root; non-root processes are not allowed to bind to privileged ports. Another great way to deal with this is to implement either mod_jk or setup a reverse proxy using apache.