ec2 web server on port 80 not reachable - amazon-web-services

ec2 instance is not publically available
I have a simple flask server open to port 80
there is even a public ip address but if I curl remotely to it connection get refused
but strangely ssh works just fine
and if I curl to public ip inside ec2 ssh it works
tried editing security group inboud rules but doesn't work...
googled bunch but all solutions say to edit inbound rules but it doesn't work for me...
am I doing something wrong?

The most common reason for this is that your Flask app is listening on localhost only, which is the default, and so is not reachable from outside the machine it's running on.
To fix this, make the server externally visible, by using:
app.run(host='0.0.0.0')

Related

Simply getting a new EC2 windows instance up and running hosting a simple Hello World web app, and unable to connect to it from any other machine

Problem: Simply getting a new EC2 windows instance up and running hosting a simple Hello World web app, and unable to connect to it from any other machine
Ok, I feel foolish asking this, as I've gotten this to work many times for years. But today, for no discernable reason, I am stumped.
New Windows Server 2022 base instance.
Run simple .net web app listening on port 80
Locally browse to http://localhost and it works fine
Turn on Firewall rule to allow port 80
In AWS Security Groups, allow port 80
Test with the public IP: Site cannot be reached
Disable Windows Firewall completely: same result
Use an alternative port, 5001, 8080, allowing them in the firewall, and with AWS security rules: same result
Try from another EC2 instance in the same subnet: same result
Make sure that locally the simple web app is working: yes
As I mentioned I feel like I am missing some critical and obvious thing.
Please be kind, as I have tried many solutions for this and am hitting a wall, and am humbly asking for help, not ridicule.
Here is the firewall of and connecting locally:
Here is the security groups:
Here is the subnet network ACL:
Here is the not connecting:
Found the answer. I was running my aspnet.core app using:
app.Run("http://localhost:5001")
But should have been using:
app.Run("http://0.0.0.0:5002")
The first tells the app to listen ONLY on IP 127.0.0.1, while the second says listen on ALL IP addresses.
After much searching I found the clue here:
https://weblog.west-wind.com/posts/2016/sep/28/external-network-access-to-kestrel-and-iis-express-in-aspnet-core
Specifically this:
In order to expose Kestrel externally you either have to bind to a specific machine name, IP Address or 0.0.0.0 which stands for all IP Addresses (thanks to #DamianEdwards and #BradyMHolt for their help).
So it really is just these threes main things needed:
Windows Firewall allow port
App running on port
AWS Security Rules for port
However, the way the the application binding is made is critical!
This is also helpful:
What is the difference between 0.0.0.0, 127.0.0.1 and localhost?

EC2 Server Instance running RStudio on port 8787 Timing Out

I am attempting to run RStudio on an AWS EC2 instance, but it keeps timing out. I am currently following the instructions in this post (https://aws.amazon.com/blogs/big-data/running-r-on-aws/).
From my research, I realize that this is most often a security group issue.
My instance has access to SSH port 22 and Custom TCP port 8787. I've been troubleshooting using this link (https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/TroubleshootingInstancesConnecting.html#TroubleshootingInstancesConnectionTimeout).
I have tried using both default VPC and my own, both of which have the following subnet network ACL rules.
However, my public IPVv4 DNS (http://ec2-18-234-130-212.compute-1.amazonaws.com/) keeps timing out. I cannot access the login page.
A friend who set up their instance using the first link was successful, and as far as I can tell, I have done everything the same.
Any help is greatly appreciated!
Your RStudio works fine. In your URL you have to provide port number: 8787
http://ec2-18-234-130-212.compute-1.amazonaws.com:8787
As you wrote in the question, it seems you are using the link without the port number.
p.s.
As you've setup it currently, your traffic to RStudio goes unencrypted over HTTP. If you are not fine with that, a quick fix would be to use ssh tunnel from the instance to your local workstation. With this can close port 8787 as all traffic goes over port 22 and ssh.
Do you access the login page in web browser? If you doing that, you forgot to open port 80/443

Deploying a Go app in AWS ec2 got connection refused

I have a compiled Go project that I want to deploy to an AWS EC2 instance. I just simply upload the application and run ./application on the remote server.
In the terminal, the application is running and says he's listening to localhost:3000.
I've already added the 3000 port to the security group.
However, when I tried to access it in my browser using <public-ip>:3000, it always shows connection refused, whether I've run the application or not.
I tried to run the app locally, it does work.
So is it because I deploy it incorrectly?
It is a bit difficult to help you because of no code being shared.
Some reasons why you got connection refused:
Your application is listening only localhost:3000
EC2 security group does not expose port 3000
How to fix:
Most applications are defining the host address on a config file or env variables. If you have access to change it, change it from localhost:3000 to 0.0.0.0:3000 to accepts connection from all IP or to your_ec2_public_ip:3000
If host address is hardcoded and you have access to code, change the code per above
If you don't have access to config or code to change the host address, then add a reverse proxy to route the incoming call to localhost:3000. This is a good link about using Nginx as reverse proxy https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/
Ensure EC2 Security Group allowing inbound connection for the designated port, in this case, is 3000 if you manage to route the incoming to your_ip:3000

Connection getting refused to socket.io server on Amazon EC2

I have set up a a micro EC2 instance on AWS. Currently, I am using the free tier in Oregon. There are two problems which I am facing.
When I try to SSH the instance using the public DNS, it says host does not exist but when I try conencting it using the public IP, it connects to it. What setting is needed to use the public DNS ?
I have opened the SSH client using the IP address. I want to set up my application which needs Node.js and MongoDB. I installed Node.js using this
Next I installed MongoDB using this
Then I connected to my instance using Filezilla and uploaded my code to it. I then start my node application which uses socket.io.
When I try to connect to socket.io server using web browser, I get a message which says connection refused "error 111". I have opened TCP port 80 in instance's security groups. In iptables, I have forwarded port 80 to 8080, but still it does not work. I have also checked that the firewall is disabled in ec2. Kindly help me to resolve this issue.
Did you check if all of the necessary ports are open on Amazon Security Policy?
What you can do is to allow all traffic on Amazon Security Policy for test and see if the connection goes well or not.
You might also check if you need access DB from outside. In that case, you also have to open the mongodb port and setup mongodb correctly as well.
Other tools that might useful to test firewall and connection issue will be tcpdump and syslog file
For the dns issue, did you try to nslookup on that name and see if the IP shown matches your server IP?
As Amazon gives a long DNS hostname for the server, I always use my own domain name. It's much easier.
example : ec2.domainname.com, which points to the Amazon IP address
Hope that help.
My problem is resolved now..
For the DNS issue, earlier I needed proxy to access internet, so I guess the DNS name was not getting resolved. When I tried using proxy free internet, I was able to ssh using public DNS.
And regarding connection to socket.io, I used port 8080 instead of 80 and used "sudo node main.js" to run my node file. Now I am able to connect to the socket.io server and MongoDB.
Another thing which I want to ask is that would running the node file with sudo rights create some security issue ?
Thanks for the answer! That also worked for me. I had the same problem trying to connect through sockets (http://myipaddress:3000) to a node.js server, i tried opening ports on the actual ec2 instance and disabling the firewall through SSH but nothing worked. Had to go to Security Groups on the ec2 console and open a new inbound tcp rule enabling that port

Unable to access JBOSS server deployed on Amazon EC2

I have deployed jboss-4.2.3 on an EC2 instance. I have added appropriate rule to open port 8080 for inbound traffic. When I ssh into this instance and do curl localhost:8080, the expected response can be seen
But when I try to access it in a browser on my laptop, am unable to connect. Few other things I have tried to eliminate other possibilities
In order to eliminate possibility of firewall issues on my laptop, have tried to connect from another instance on amazon. Doesnt work
Also tried to configure jboss to listen to port 80. Still it can't be accessed. Apache running on port 80 however responds
Any guidance is highly appreciated
Bind your jboss to all IP addresses as below:
./run.sh -b 0.0.0.0
I was struggling with the same issue.
You need to open up port 8080 in the Security Groups as Wildfly is using it. Then you should be able to access the page.