4

I'm aware of the implications of running tomcat on port 80, but I'm after a quick solution. I'm trying to follow this tutorial. I've followed the tutorial with two changes:

  • tomcat6 is user name tomcat is run as
  • The location of tomcat conf file: /usr/share/tomcat6/bin/catalina.sh

But I'm still getting permissions errors. Java is saying its unable to bind to port 80. What else should i be doing? What other information should i provide for people to debug? Just to confirm, there's nothing else running on port 80

4
  • and you are doing this with root privileges?
    – Thomas
    Nov 30, 2011 at 21:12
  • how do you mean? im logged in as root when configuring the server?
    – richzilla
    Nov 30, 2011 at 21:23
  • No, when starting the server. In the tutorial it is this part: sudo /etc/init.d/tomcat6 restart
    – Thomas
    Nov 30, 2011 at 21:33
  • yes, im logged in as root when i restart the server (so i dont need the sudo part)
    – richzilla
    Nov 30, 2011 at 21:37

4 Answers 4

6

You can change AUTOBIND property of /etc/default/tomcat6 to "yes" as follows:

AUTHBIND=yes

Restart your tomcat and that will enable you to use available privileged port (1-1023).

1
  • I done that thing as well. Still not getting. @richzilla : if your code is working please let me know and mark this one as verified so that we can discuss further on this answer. May 23, 2014 at 5:30
2

There are two different ways of doing this without actually touching the tomcat config.

You can make an iptables script that redirects traffic from port 80 to port 8080 (then you dont need to fiddle around with tomcat settings)

for iptables

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8080 -j REDIRECT --to-port 80 would do the trick! (make a script so its done automatically on uppstart

or you can create a Apache reverse proxy that actually proxies the connections to your tomcatserver through it (this is good since it can actually cache request and speed up connections for you)

1
  • Shouldn't 8080 and 80 port should be switched in the provided script? i.e. iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080 Jan 20, 2014 at 18:14
0

In the Tomcat HTTP connector, make sure your connector on port 80 is binding to ALL interfaces, or 0.0.0.0 , rather than just 127.1 . That might explain why your not able to connect with a url such as http://10.0.0.2:80 but you can with http://127.1:80

0

Start tomcat services using authbind this will allow user to start ports less than 1024 we do not need to redirect or iptables.

apt-get install authbind -y

To install Authbind software

chmod -R 755 /etc/authbind

group should be user group.

chown -Rh root:group /etc/authbind

After that run the below commands

cd /etc/authbind/byuid

As an example lets imagne user id is 2000 you can use your user id number

echo '0.0.0.0/0:1,1023' > 2000

That file should be own by user and group.

chown : 2000

chmod 700 2000

Add the below line in tomcat startup file $CATALINA_BASE/startup.sh

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

For Starting tomcat using Authbind service startup.sh

Comment the below line

#$CATALINA_HOME/bin/startup.sh

Add This End as the end of the file

AUTHBIND_COMMAND="/usr/bin/authbind --deep /bin/bash -c " 

$AUTHBIND_COMMAND $CATALINA_HOME/bin/startup.sh   

now you should be able to start tomcat services as user with less that 1024 ports.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .