Friday, May 27, 2011

Redirecting port 80 on Linux

I recently installed a JEE application and wanted it to run on port 80 to simplify the URL. For security reasons I didn't want the process to run as root. When I tried to change the application servers config to attempt to bind port 80 I would receive this error:
Non root user cannot bind to port 80

After doing some research, I finally found the solution I decided to move forward with on Server Fault.

This allowed me to use iptables to redirect port 80 requests to port 8080:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

Now I'm a happy admin as I get the security of not running the process as root and the pretty URL that doesn't require specifying the port!

No comments:

Post a Comment