Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tomcat Webapp on port 80 [duplicate]

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.

like image 731
eLRuLL Avatar asked May 01 '13 21:05

eLRuLL


People also ask

Can Tomcat run on port 80?

Tomcat, in a default installation, is configured to listen on port 8080 rather than the conventional web server port number 80.

How do I host my Tomcat website on port 80?

Start Tomcat on port 80 You can simply configure Tomcat to start on port 80 through modifying the “Connector” tag inside server. xml. Go to $/conf and open server. xml.


2 Answers

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="/" />
like image 77
ilikeorangutans Avatar answered Oct 31 '22 17:10

ilikeorangutans


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.

like image 11
NilsH Avatar answered Oct 31 '22 19:10

NilsH