10

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
  • 18,488
  • 9
  • 73
  • 99

3 Answers3

11

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.

NilsH
  • 13,705
  • 4
  • 41
  • 59
  • 1
    Great, I think I'll use authbind, using these steps: http://java.dzone.com/articles/running-tomcat-port-80-user – eLRuLL May 01 '13 at 21:40
7

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="/" />
ilikeorangutans
  • 1,753
  • 1
  • 11
  • 14
  • 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. – eLRuLL May 01 '13 at 21:41
  • 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. – ilikeorangutans May 02 '13 at 01:08
1

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.

eLRuLL
  • 18,488
  • 9
  • 73
  • 99
NullPointerException
  • 3,732
  • 5
  • 28
  • 62