Reputation: 4176
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
Upvotes: 0
Views: 175
Reputation: 2830
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 directorye.g. C:\Tomcat 6.0\conf\
2) Edit following tag in
server.xml
file3) Change the
port=8080
value toport=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
Upvotes: 2
Reputation: 4176
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
Note: My Ec2 instance's security group's inbound rules were accepting HTTP
at port 80
from anywhere.
Upvotes: 0