Thursday, August 23, 2007

Tomcat: Redirect all requests to port 80 on port 8080

... the IPTables way! (there are other solutions)
Configure the iptables behavior in file /etc/sysconfig/iptables-config to save the new rules

IPTABLES_SAVE_ON_STOP="yes"
IPTABLES_SAVE_ON_RESTART="yes"
IPTABLES_SAVE_COUNTER="yes"

Manually add the following rules:

> iptables -t nat -A OUTPUT -d localhost -p tcp --dport 80
-j REDIRECT --to-ports 8080
> iptables -t nat -A OUTPUT -d <your_ip> -p tcp --dport 80
-j REDIRECT --to-ports 8080
> iptables -t nat -A PREROUTING -d <your_ip> -p tcp --dport 80
-j REDIRECT --to-ports 8080


Save and restart the service:

> /etc/init.d/iptables save
> /etc/init.d/iptables restart

1 comment:

Andrea Caltroni said...

Thank you Karsten.