【发布时间】:2019-05-21 08:07:36
【问题描述】:
这周我一直在设置 AWS EC2 服务器,而我想做的事情几乎完成了。但事实证明,作为 Web 服务器开放是一个绊脚石。
我的设置
我有一个运行 Red Hat EL7 的 AWS EC2 实例。
我的实例上运行着 Apache 服务器:
[ec2-user@ip-172-xx-xx-xx ~]$ ps -ef | grep -i httpd
root 18162 1 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18163 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18164 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18165 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18166 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
apache 18167 18162 0 18:02 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
ec2-user 21345 20507 0 19:03 pts/1 00:00:00 grep --color=auto -i httpd
好像在监听 80 端口:
[root@ip-172-xx-xx-xx ~]# netstat -lntp | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 18162/httpd
我为端口 80 (HTTP) 和 443 (HTTPS) 的“launch-wizard-1”安全组(显示为实例的安全组)添加了入站规则,源为“0.0.0.0/0 " 和 "::/0"
最后,为了测试我的设置,我在文档根目录 (/var/www/html) 中创建了一个 index.html 文件:
<html>
<h1>TEST!</h1>
</html>
问题
当我尝试点击时,从我电脑上的 chrome 浏览器:
http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com/index.html
我刚刚得到:
This page isn’t working
ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com didn’t send any data.
ERR_EMPTY_RESPONSE
(当我点击我在那里设置的一个域名时,我得到了同样的结果,这当然是我真正想要做的!)
我尝试从 2 台不同计算机上的 Chrome 和我手机上的 Safari 进行连接(“Safari 无法打开页面,因为它无法连接到服务器”)
我已执行的检查
我认为我没有任何服务器防火墙阻止此操作:
[root@ip-xx-xx-xx-xx conf]# /sbin/iptables -L -v -n
Chain INPUT (policy ACCEPT 3575 packets, 275K bytes)
pkts bytes target prot opt in out source destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 2215 packets, 350K bytes)
pkts bytes target prot opt in out source destination
在我的 Mac 上的终端会话中使用 telnet 进行测试,端口 80 似乎已打开。首先使用 IPv2 公网 IP:
telnet 18.xxx.xxx.xx 80
Trying 18.xxx.xxx.xx...
Connected to ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com.
Escape character is '^]'.
Connection closed by foreign host.
并使用公共 DNS (IPv4):
telnet ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com 80
Trying 18.xxx.xxx.xx...
Connected to ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com.
Escape character is '^]'.
Connection closed by foreign host.
同样,我的域名也是如此 - telnet 到端口 80 显示“已连接”。
- “外部主机”立即关闭连接这一事实是否重要?如果一切正常,它是否应该保持打开状态?
在主机上运行 curl 正确返回我的简单 index.html 文件:
[ec2-user@ip-172-xx-xx-xx ~]$ curl localhost
<html>
<h1>TEST!</h1>
</html>
但是,在我的本地计算机上运行 curl - 到服务器 - 返回:
curl -v http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com:80
* Rebuilt URL to: http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com:80/
* Trying 18.xxx.xxx.xx...
* Connected to ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com (18.xxx.xxx.xx) port 80 (#0)
> GET / HTTP/1.1
> Host: ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com
> User-Agent: curl/7.43.0
> Accept: */*
>
* Empty reply from server
* Connection #0 to host ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com left intact
curl: (52) Empty reply from server
我还通过在服务器上运行 google chrome(无头)来“内部”测试网络服务器以创建屏幕截图,下载到我的本地计算机并显示 TEST! (即它的工作):
google-chrome-stable --headless --disable-gpu --screenshot http://localhost
还要补充一点 - 当我尝试从本地计算机访问网络服务器时,服务器上的网络服务器日志(error_log 或 access_log)中没有显示任何内容。
所以,我认为 Web 服务器已启动并运行,在本地工作,但对于来自“外部”的任何内容都无法正常工作。不过我现在很难过。
【问题讨论】:
-
如果您从服务器本身尝试
curl localhost会发生什么?这样,它就可以在不受任何网络配置影响的情况下测试 Web 服务器。 -
对不起 - 应该说我已经这样做了,而且效果很好;返回了我的简单 index.html 的 HTML
标签: apache amazon-web-services amazon-ec2 webserver httpd.conf