![从 Amazon EC2 实例连接到外部 Web 服务时出现问题](https://linux22.com/image/552310/%E4%BB%8E%20Amazon%20EC2%20%E5%AE%9E%E4%BE%8B%E8%BF%9E%E6%8E%A5%E5%88%B0%E5%A4%96%E9%83%A8%20Web%20%E6%9C%8D%E5%8A%A1%E6%97%B6%E5%87%BA%E7%8E%B0%E9%97%AE%E9%A2%98.png)
我正在尝试访问https://test.httpapi.com来自我的一个运行基本 Amazon Linux AMI 的 Amazon EC2 实例的 webservice。这是 nc 命令的输出:
[root@ec2-instance]# nc -v test.httpapi.com 80
nc: connect to test.httpapi.com port 80 (tcp) failed: No route to host
[root@ec2-instance]# nc -v test.httpapi.com 443
nc: connect to test.httpapi.com port 443 (tcp) failed: No route to host
[root@ec2-instance]# nc -v test.httpapi.com 22
nc: connect to test.httpapi.com port 22 (tcp) failed: Connection refused
因此,当我尝试端口 80 或 443 时,出现“没有到主机的路由”的错误,但是当我尝试 ssh 端口 22 时,出现“连接被拒绝”的错误(这是预料之中的)。
但是,如果我从本地计算机(运行 Ubuntu Linux)尝试,我可以成功连接到端口 80 和 443:
me@my-laptop$ nc -v test.httpapi.com 80
Connection to test.httpapi.com 80 port [tcp/www] succeeded!
me@my-laptop$ nc -v test.httpapi.com 443
Connection to test.httpapi.com 443 port [tcp/https] succeeded!
me@my-laptop$ nc -v test.httpapi.com 22
nc: connect to test.httpapi.com port 22 (tcp) failed: Connection refused
iptables 在 EC2 实例上被禁用。
这可能是什么问题?
答案1
问题不在于 EC2 实例。我也无法连接到主机:
MacBook-Pro-van-Bart:~ ikbenbart$ nc -v test.httpapi.com 80
nc: connect to test.httpapi.com port 80 (tcp) failed: Connection refused
MacBook-Pro-van-Bart:~ ikbenbart$ nc -v test.httpapi.com 443
nc: connect to test.httpapi.com port 443 (tcp) failed: Connection refused
MacBook-Pro-van-Bart:~ ikbenbart$ nc -v test.httpapi.com 22
nc: connect to test.httpapi.com port 22 (tcp) failed: Connection refused
您尝试连接的主机67.15.184.38
对我来说是:
MacBook-Pro-van-Bart:~ ikbenbart$ dig test.httpapi.com
; <<>> DiG 9.6.0-APPLE-P2 <<>> test.httpapi.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46683
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;test.httpapi.com. IN A
;; ANSWER SECTION:
test.httpapi.com. 28116 IN A 67.15.184.38
;; Query time: 9 msec
;; SERVER: 192.168.220.52#53(192.168.220.52)
;; WHEN: Mon Jun 13 13:56:28 2011
;; MSG SIZE rcvd: 50
但这指向另一个主机:
MacBook-Pro-van-Bart:~ ikbenbart$ host 67.15.184.38
38.184.15.67.in-addr.arpa is an alias for 38.184.15.67.in-addr.ev1.opticaljungle.com.
38.184.15.67.in-addr.ev1.opticaljungle.com domain name pointer qmail-d.directi.com.
如果可能的话,请查看您对 67.15.184.38 所做的设置。