Restarted Database Server can no longer be accessed by webserver - django

I had to stop then start my ec2 database server running postgresql. Now after it is started, i get the following error message from my django web server
could not connect to server: Connection refused Is the server
running on host "54.235.119.193" and accepting TCP/IP connections on
port 5432?
However because I use elastic IPs and reassigned the same IP (54.235.119.193) I don't think that is the issue. I also am using the same security groups as before, which allow 5432.
I think the only thing that changes when you start/stop is the internal IP but I don't remember using that anywhere in configuration
Any Ideas?

Are you using iptables or selinux? These usually get in the way on restart if not configured properly.

Related

How do you connect an amazon rds to a django app

I have added the correct name, engine, user, password etc. Then I modified the inbound security rules to give my computer access to the database and I still cant connect the postgres database to the django app does anyone know what could cause this?
I keep getting this error
port 5432 failed: Connection timed out
Is the server running on that host and accepting TCP/IP connections?

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 to a webapp running on AWS being refused

I have a webapp that I run on port 8000. So i start it with the command:
> smtweb
Performing system checks...
System check identified no issues (0 silenced).
October 12, 2017 - 11:25:27
Django version 1.8.18, using settings None
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Then I try to access the webapp as follows through the public elastic IP that I've associated with the running instance:
http://34.XXX.XXX.XXX:8000/
(I've omitted parts of the IP for my own safety, through XXX)
However, Chrome throws the following error:
34.XXX.XXX.XXX refused the connection.
ERR_CONNECTION_REFUSED
So the connection is refused, even tough I've associated the machine with a security group that has the following rule:
Type: Custom TCP Rule
Protocol: TCP
Port Range: 8000
Source: 0.0.0.0/0
Now, I'm not sure if I have to configure something more in the AWS Tools. It seems that I've done everything there. What I'm asking myself is:
Does the app have some restrictions by itself?
I have an Ubuntu image: Do I have to adjust some more firewall settings there?
Do you have an idea what I could try next?
ERR_CONNECTION_REFUSED means that there is no port open and NOT that the port is blocked by a security group rule. The TCP/IP stack has rejected the connection request.
Double check that you really have port 8000 configured for the interface that you are assigning the EIP.
Try to access your app from the same machine using the destination IP of both the local IP address and EIP.
If the local IP works and the EIP does not, check your network configuration. Your web app might not be binding to the interface assigned to the EIP and might still be configured for the old public IP address or not configured at all.
If both IP addresses work, then the problem is most likely not with your web application. Look at iprules, firewalls, etc. running on your local machine.

Tableau desktop not connecting to DB server on AWS instance

My postgres DB is in AWS instance running windows server 2012.
My tableau desktop is in local machine.
While connecting to the DB using external instance IP and default postgres PORT 5432 , it shows the error
Unable to connect to the ODBC Data Source.
Check that the necessary drivers are installed and that the connection properties are valid.
Unable to connect to the server "ec2-xx.xx.xx.xx.ap-south-1.compute.amazonaws.com".
Check that the server is running and that you have access privileges to the requested database.
I have made sure that:
AWS security group is configured for all incoming ports
Windows server 2012 firewall is accepting all inbound traffic.
My local desktop is allowing to send traffic to remote server.And I can telnet hostIP/hostname PORT successfully.
Postgres service is running on 5432 port.
Going by the points you mentioned, I would suggest to see if you have the required drivers installed for postgres. Also, if possible for you for the time being you can install any client temporarily like sqldeveloper(later you can remove this) on the tableau desktop.
Now because you are able to telnet Ip 5432, you can test your connection from the client, If this doesnt work u know that the problem is in configuration else we need to dig more into that.
It seems like I have not set the pg_hba.conf file correctly for postgres. Allowing the connection request from all external IPs let me resolve the issue.
Adding the line at the end of the file,
host all postgres 0.0.0.0 md5

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