prayagupadhyay
prayagupadhyay

Reputation: 31262

amazon ec2 - Couldn't resolve host

I'm a nooob devops guy in town. I've a nodejs app running on amazon instance pointing to DNS's. Prayag

                                Route53 screenshot

Problem

when I try to reach the subdomain, I get

curl -i http://site.soothsayer.co/
curl: (7) Failed connect to site.soothsayer.co:80; Connection timed out

or

$ curl -i http://site.soothsayer.co/
HTTP/1.1 502 Bad Gateway
Connection: Keep-Alive
Content-Type: text/html; charset=utf-8
Via: 1.1 Comverse 6.2.23
Content-Length: 287

<!DOCTYPE html PUbliC "-//W3C//Dtd XHTML basic 1.0//EN"
"http://www.w3.org/tr/1999/REC-html401-19991224/loose.dtd">
<html>
<head>
<title>Error</title>
</head>
<body leftmargin="0" topmargin="0" style="font-family:arial">
Error: Requested url content cannot be resolved.
</body>
</html>

Debugging

nslookup result is

Server:     127.0.1.1
Address:    127.0.1.1#53

Non-authoritative answer:
site.soothsayer.co  canonical name = internal-p-site-us-east-1-1077850846.us-east-1.elb.amazonaws.com.
Name:   internal-p-site-us-east-1-1077850846.us-east-1.elb.amazonaws.com
Address: 172.31.46.66

I can see proper html response from GET http://localhost:3000 or GET http://localhost:8085 (configured in nginx) within the amazon machine.

I'm using nginx/1.4.7 as HTTP and reverse proxy server (as per my understanding), conf file being

$ vi /etc/nginx/conf.d/site.soothsayer.co.conf
# the IP(s) on which your node server is running. I chose port 3000.
upstream site.soothsayer.co {
     server 127.0.0.1:3000;
}
# the nginx server instance
server {
    listen 0.0.0.0:8085;
    server_name site-proxy.soothsayer.co site-proxy.soothsayer.co;
    access_log /var/log/nginx/site-proxy.soothsayer.co.log;

    # pass the request to the node.js server with the correct headers and much more can be added, see nginx config options
    location / {
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_set_header X-NginX-Proxy true;

      proxy_pass http://site.soothsayer.co/;
      proxy_redirect off;
    }
}

My /etc/resolv.conf is,

; generated by /sbin/dhclient-script
search ec2.internal
nameserver 172.31.0.2

iptables of amazon machine,

[root@ip-172-31-42-77 rof]# iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 

Security Group on amazon is default,

Custom TCP Rule TCP 8086 0.0.0.0/0

I don't see any logs at /var/log/nginx/error.log. This is what my little brain could debug. I want to fix this issue.

References

nginx, dns - domain.com resolves but subdomain.domain.com doesn't

AWS - elastic load balancer unable to handle the request

amazon ec2 instance unable to resolve host

Curl amazon EC2 instance

Upvotes: 0

Views: 2999

Answers (2)

prayagupadhyay
prayagupadhyay

Reputation: 31262

So, issue was with load balancer being internal. Made it internet-facing. Everything looks Majestic now.

enter image description here

References

Internet-facing and Internal Load Balancers

Upvotes: 1

Pixou
Pixou

Reputation: 1769

not sure, but your nginx conf with listen 0.0.0.0:8085 may block any remote access. Try :

listen 8085;

Upvotes: 0

Related Questions