Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux in EC2(Amazon) cannot use port 80 for tomcat [closed]

First, i just want to see it is not security group setup in ec2 console. because i can setup the apache, which is by fault 80 port, and be able to visit the apache website through 80 port. but for tomcat it works if i use port 8080(by default) or some values bigger than 1023(i think this port). but when i change server.xml(changing 8080 to 80) it cannot work if i use 80 port, i start the service successfully, but there is no 80/http listening. I know it should be some privileges issues(only the root can start service below 1023 port). but i did not know how to do it.

like image 726
Hypnoz Avatar asked Sep 17 '12 18:09

Hypnoz


2 Answers

My personal choice for this problem is to use iptables to redirect all traffic from port 80 to the upper port (e.g. 8080) the Tomcat is running on.

/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
like image 198
mindas Avatar answered Oct 26 '22 12:10

mindas


The way I did this previously was to use Apache2 as a proxy using virtual hosts, and proxy onto Tomcat. this will handle the requests and then can also be used as a load balancer if in the future you decide to use multiple Tomcats for load balancing.

like image 28
david99world Avatar answered Oct 26 '22 11:10

david99world