skip to Main Content

I have my webapp running on Tomcat which is running on an EC2 instance.
I have set up my instance’s inbound rules properly.

When I enter <myWebsite.com>:8080 it works from my browser.
For <myWebsite.com> it does not load. Rather I get the following error message:

This site can’t be reached <myWebsite.com> refused to connect.
Search Google for <my Website> home
ERR_CONNECTION_REFUSED

2

Answers


  1. Chosen as BEST ANSWER

    Ok, After following several answers in StackOverflow, following worked

    sudo /sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
    sudo /sbin/iptables-save
    

    Following didn't work

    1. Assigning Elastic Ip for VPC and using it to connect to the instance.
    2. Changing tomcat server.xml port from 8080 to 80.

    Note: My Ec2 instance's security group's inbound rules were accepting HTTP at port 80 from anywhere.


  2. When you try to connect directly via myWebsite.com, your browser will default to http on port 80. Apparently, your webserver is listening on port 8080 though.

    You need to configure Tomcat to listen for incoming requests on port 80.

    There are many tutorials and questions here on stackoverflow about how to change the tomcat port from 8080 to 80.

    E.g from How to change the port of Tomcat from 8080 to 80?:

    1) Go to conf folder in tomcat installation directory

    e.g. C:Tomcat 6.0conf
    

    2) Edit following tag in server.xml file

    3) Change the port=8080 value to port=80

    4) Save file.

    5) Stop your Tomcat and restart it.

    Keep in mind that, by default, Tomcat will not start on port 80, unless run as root. However, running as root is generally considered bad practice.
    The following resource summarizes well how to mitigate this problem with Tomcat and EC2:
    https://www.excelsior-usa.com/articles/tomcat-amazon-ec2-advanced.html#port80

    The easiest solution would be to redirect the tomcat port (e.g.8080) via iptables:

    sudo /sbin/iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
    sudo /sbin/service iptables save
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search