Monday, 6 May 2013

[How To] - Fix GlassFish not listening to port 80 after updating security group's rule on Amazon EC2 instance

In one of my projects, after I've correctly updated the security groups's rules on my Amazone Linux EC2 instance to allow incoming connections to port 80 (HTTP) and 443  (HTTPS), my requests to these 2 ports are still ignored. If you do a sudo netstat -lntp, you will see that there is a process listening on port 4848 which is your GlassFish app server but it is NOT listening to port 80 and 443! Why!!?

If you take a look at the app server's log file right after starting it, you will see the Connection refuse exception. Assuming that you've already correctly set up GlassFish's http-listeners to listen to port 80 and 443, the solution is actually pretty simple: you have to start the server using the root privilege (i.e. sudo ./<GLASSFISH-FOLDER>/bin/asadmin start-domain). These 2 special ports seem to be protected by Linux OS. You cannot listen to these 2 ports without having access to root privilege.

I hope this helps! :)..