[tomcat] How to change the port of Tomcat from 8080 to 80?

I want to execute my web app as http://localhost.

This question is related to tomcat tomcat6

The answer is


On a Linux Debian-based (so Ubuntu included) you have also to go to /etc/default/tomcat7, uncomment the #AUTHBIND=no line and set its value to 'yes', in order to let the server bind on a privileged port.


Running the command below worked with. Tried changing server.xml and the conf file but both didn't work.

/sbin/iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT

/sbin/iptables -A INPUT -i eth0 -p tcp --dport 8080 -j ACCEPT

/sbin/iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080

if you are using eclipse and modifying server.xml doesn't work for you then try following article.. they have steps to modify port if you are using IDE like eclipse.


Don't forget to edit the file. Open file /etc/default/tomcat7 and change

#AUTHBIND=no

to

AUTHBIND=yes

then restart.


Here are the steps:

--> Follow the path: {tomcat directory>/conf -->Find this line:

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

change portnumber from "8080" to "80".

--> Save the file.

--> Restart the server :)


Just goto conf folder of tomcat

open the server.xml file

Goto one of the connector node which look like the following

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

Simply change the port

save and restart tomcat


On Ubuntu and Debian systems, there are several steps needed:

  1. In server.xml, change the line <Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/> to have port="80".

  2. Install the recommended (not required) authbind package, with a command like:

    sudo apt-get install authbind

  3. Enable authbind in the server.xml file (in either /etc/tomcat6 or /etc/tomcat7) by uncommenting and setting the line like:

    AUTHBIND=yes

All three steps are needed.


On modern linux the best approach (for me) is to use xinetd :

1) create /etc/xinet.d/tomcat-http

service http
{
        disable = no
        socket_type = stream
        user = root
        wait = no
        redirect = 127.0.0.1 8080
}

2) create /etc/xinet.d/tomcat-https

service https
{
        disable = no
        socket_type = stream
        user = root
        wait = no
        redirect = 127.0.0.1 8443
}

3) chkconfig xinetd on

4) /etc/init.d/xinetd start


Ubuntu 14.04 LTS, in Amazon EC2. The following steps resolved this issue for me:

1. Edit server.xml and change port="8080" to "80"

sudo vi /var/lib/tomcat7/conf/server.xml

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

2. Edit tomcat7 file (if the file is not created then you need to create it)

sudo vi /etc/default/tomcat7

uncomment and change #AUTHBIND=no to yes

3. Install authbind

sudo apt-get install authbind

4. Run the following commands to provide tomcat7 read+execute on port 80.

sudo touch /etc/authbind/byport/80
sudo chmod 500 /etc/authbind/byport/80
sudo chown tomcat7 /etc/authbind/byport/80

5. Restart tomcat:

sudo /etc/init.d/tomcat7 restart

I tried changing the port from 8080 to 80 in the server.xml but it didn't work for me. Then I found alternative, update the iptables which i'm sure there is an impact on performance.

I use the following commands:

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

http://www.excelsior-usa.com/articles/tomcat-amazon-ec2-advanced.html#port80


On a linux server you can just use this commands to reconfigure Tomcat to listen on port 80:

sed -i 's|port="8080"|port="80"|g' /etc/tomcat?/server.xml
sed -i 's|#AUTHBIND=no|AUTHBIND=yes|g' /etc/default/tomcat?
service tomcat8 restart

If someone is looking for, how to change the tomcat port number in Eclipse IDE user following are the steps.

1.In the Servers view, double click on the server name: enter image description here

2.That will open a configuration page for Tomcat as follows: enter image description here

3.Notice the port numbers are shown in the table on the right. Click to edit, for example: enter image description here

4.That will change port number for HTTP from 8080 to 80. Press Ctrl + S to save the change and restart the server. We can spot the change of port number in the Console view: enter image description here

This all content were taken from below link, please refer that link for further information thanks. http://www.codejava.net/servers/tomcat/how-to-change-port-numbers-for-tomcat-in-eclipse


As previous answers didn't work well (it was good, but not enough) for me on a 14.04 Ubuntu Server, I mention these recommendations (this is a quote).

Edit: note that as @jason-faust mentioned it in the comments, on 14.04, the authbind package that ships with it does support IPv6 now, so the prefer IPv4 thing isn't needed any longer.

1) Install authbind
2) Make port 80 available to authbind (you need to be root):

  touch /etc/authbind/byport/80
  chmod 500 /etc/authbind/byport/80
  chown tomcat7 /etc/authbind/byport/80

3) Make IPv4 the default (authbind does not currently support IPv6).
   To do so, create the file TOMCAT/bin/setenv.sh with the following content: 

   CATALINA_OPTS="-Djava.net.preferIPv4Stack=true"

4) Change /usr/share/tomcat7/bin/startup.sh

  exec authbind --deep "$PRGDIR"/"$EXECUTABLE" start "$@"
  # OLD: exec "$PRGDIR"/"$EXECUTABLE" start "$@"

If you already got a setenv.sh file in /usr/share/tomcat7/bin with CATALINA_OPTS, you have to use :

export CATALINA_OPTS="$CATALINA_OPTS -Djava.net.preferIPv4Stack=true"

Now you can change the port to 80 as told in other answers.


Examples related to tomcat

Jersey stopped working with InjectionManagerFactory not found The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. on deploying to tomcat Spring boot: Unable to start embedded Tomcat servlet container Tomcat 404 error: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists Spring Boot application in eclipse, the Tomcat connector configured to listen on port XXXX failed to start Kill tomcat service running on any port, Windows Tomcat 8 is not able to handle get request with '|' in query parameters? 8080 port already taken issue when trying to redeploy project from Spring Tool Suite IDE 403 Access Denied on Tomcat 8 Manager App without prompting for user/password Difference between Xms and Xmx and XX:MaxPermSize

Examples related to tomcat6

There are No resources that can be added or removed from the server Proxy Error 502 : The proxy server received an invalid response from an upstream server HTTP Status 500 - org.apache.jasper.JasperException: java.lang.NullPointerException How to solve could not create the virtual machine error of Java Virtual Machine Launcher? The network adapter could not establish the connection - Oracle 11g Best way to increase heap size in catalina.bat file CATALINA_HOME environmental variable is not defined correctly How to change the port of Tomcat from 8080 to 80? Error With Port 8080 already in use How to set level logging to DEBUG in Tomcat?