How to access tomcat application with domain name without giving port number

I am using ubuntu 18.04 server provided by digital ocean.

I have deployed my application in tomcat running at 80.

server.xml:

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

  <Host name="mydomain.in">
      <Alias>www.mydomain.in</Alias>
      <Context path="" docBase="mydomain" debug="0" privileged="true" />
      <Valve className="org.apache.catalina.valves.AccessLogValve"
             directory="logs"   prefix="localhost_access_log." suffix=".txt"
             pattern="%h %l %u %t &quot;%r&quot; %s %b" resolveHosts="false" />
</Host>

I am able to access my application from browser with url:

www.mydomain.in:8080

But I am not able to access my domain with out port.

Please help me, if i missed any configurations.

Answer

First check if you are running any other app/server on port 80. If there is anything else running then you can’t run tomcat on 80 unless you kill the previous one.

netstat -an | grep ":80"

Even if there is nothing running on port 80, the best thing to do is to keep the port for tomcat as 8080 and redirect port 80 to it using iptables.

sudo /sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

Obviously, the normal way is to have a web server (like apache httpd) listening on port 80 and forwarding all the requests to tomcat running on 8080. That’s what I would do.

Leave a Reply

Your email address will not be published. Required fields are marked *