4

I cannot access my Django app on an EC2 instance (host2) in my browser by typing its public DNS name with port number: ec2-public-dns-of-this-instance.compute-1.amazonaws.com:8000

  1. I'm using the same Security Group that my other EC2 instance (host1) is using which is working just fine (my other Django app hosted on this instance works perfectly fine), with HTTP/TCP open on 0.0.0.0/0 on port 8000
  2. I started my Django project this way: ./manage.py runserver 0.0.0.0:8000
  3. I've added hosts into my ALLOWED_HOSTS file which has these now: ALLOWED_HOSTS = ['*', '127.0.0.1', 'ec2-public-dns-of-this-instance.compute-1.amazonaws.com', '0.0.0.0', 'localhost']
  4. I was able to curl localhost:8000 which returned me 200 and Django default HTML page when I'm ssh'ed into this instance.
  5. I was able to curl ec2-public-dns-of-this-instance.compute-1.amazonaws.com:8000 which also returned me 200 and Django default HTML page when I'm ssh'ed into this instance.
  6. both host1 and host2 are using the exactly the same subnet, VPC, SG, AMI, in the same AZ.
  7. both host1 and host2 are running on AMI Ubuntu 18.04 LTS

Any ideas how to fix this would be greatly appreciated!

Fisher Coder
  • 3,278
  • 12
  • 49
  • 84
  • Does it work if you set up ALLOWED_HOSTS = ['*'] ? – Vadim Yangunaev Jun 18 '20 at 21:12
  • Just tried it, no luck. – Fisher Coder Jun 18 '20 at 21:19
  • it really looks like port 8000 is inaccessible but you have checked your configuration. What is the host OS you are running? The configuration of the host OS seems like the only thing you have not touched on. Also, perhaps try adding port 8001 to everything and try with that ... just adding a new port will cause you to double check the configuration. – Tim Richardson Jun 19 '20 at 00:38
  • what is the error message you are seeing? is it a timeout? if you do: `curl -v ec2-public-dns:8000` what is the output? – Simon Ernesto Cardenas Zarate Jun 19 '20 at 00:41
  • host OS is Ubuntu 18.04, I've just added that into the question as well. How can I add this 8001 and what configuration to check? Could you elaborate a bit more? Thanks! – Fisher Coder Jun 19 '20 at 00:42
  • ` curl -v ec2-public-dns.compute-1.amazonaws.com:8000 * Rebuilt URL to: ec2-public-dns.compute-1.amazonaws.com:8000/ * Trying 58.237.226.90... * TCP_NODELAY set * Connection failed * connect to 58.237.226.90 port 8000 failed: Operation timed out * Failed to connect to ec2-public-dns.compute-1.amazonaws.com:8000: Operation timed out * Closing connection 0 curl: (7) Failed to connect to ec2-58-237-226-90.compute-1.amazonaws.com port 8000: Operation timed out` @SimonErnestoCardenasZarate from my Mac, of course it works fine when I ran this on this EC2 instance itself. – Fisher Coder Jun 19 '20 at 00:48
  • did you try using the public ip, instead the public dns? it sounds like the vpc might not support dns resolution, you might want to give it a try and see if it's enabled in your vpc settings – Simon Ernesto Cardenas Zarate Jun 19 '20 at 04:23
  • Yes, I tried the IP as well. No luck. – Fisher Coder Jun 19 '20 at 04:26

1 Answers1

3

Interestingly, it started working three hours later. I didn't change anything and all things remain the same as I described above. I have no clue why this is the case...

Fisher Coder
  • 3,278
  • 12
  • 49
  • 84
  • And I launched two new EC2 instances the same way and installed Django, I can access both of them on these two instances as well, immediately after I stand them up. Cannot reproduce that issue any more... – Fisher Coder Jun 19 '20 at 12:36
  • 1
    I played around this even more. Actually this is very predictable. I stood up two more fresh EC2 instances, did exactly the same thing, but I wasn't able to view my Django site via these EC2 instance's public DNS:8000 immediately, but after a couple hours, I can access them through my browser. Just wanted to share my findings here. – Fisher Coder Jun 20 '20 at 02:59