Apache 从外部浏览器访问my AWS EC2 server index.html
这周我已经安装了一台AWS EC2服务器,我几乎完成了我想做的事情。但事实证明,作为web服务器开放是一个绊脚石 我的设置 我有一个运行Red Hat EL7的AWS EC2实例 我的实例上运行了一台Apache服务器:Apache 从外部浏览器访问my AWS EC2 server index.html,apache,amazon-web-services,amazon-ec2,webserver,httpd.conf,Apache,Amazon Web Services,Amazon Ec2,Webserver,Httpd.conf,这周我已经安装了一台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
[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文件:
(当我点击我在上面设置的一个域名时,我得到了同样的结果,这当然是我真正想做的!)
我曾尝试在两台不同的计算机上使用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到端口80显示“已连接”
-“外部主机”立即关闭连接的事实是否重要?如果一切正常,它应该保持开放吗
在主机上正确运行curl将返回我的simple index.html文件:
[ec2-user@ip-172-xx-xx-xx ~]$ curl localhost
<html>
<h1>TEST!</h1>
</html>
我还通过在服务器上运行GoogleChrome(headless)来“内部”测试Web服务器,创建一个屏幕截图,下载到我的本地计算机上,它显示了测试!(即其工作原理):
还有一件事要补充——当我尝试从本地计算机命中Web服务器时,服务器上的Web服务器日志(错误日志或访问日志)中没有显示任何内容
因此,我的观点是web服务器已经启动并运行,在本地工作,但是对于来自“外部”的任何东西都不能正常工作。不过,我现在被难住了。Doh!我重新启动了实例并。。现在都开始工作了 我花了22个小时才重新启动电脑。傻瓜
终端上的ssh
连接到您的EC2实例
python
如果未安装nohup
启动python服务器以持续使用该服务器
nohup python-m http.server&
8000
,转到EC2安全组
Make sourceanywhere
或根据需要index.html
的文件夹,文件路径如下所示
--.compute-1.amazonaws.com:8000/文件夹/网站/您将能够根据需要开发和查看您的更改。如果您尝试从服务器本身
curl localhost
会发生什么?这样,它就可以在不受任何网络配置影响的情况下测试web服务器;返回my simple index.HTML的HTML
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.
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.
[ec2-user@ip-172-xx-xx-xx ~]$ curl localhost
<html>
<h1>TEST!</h1>
</html>
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-stable --headless --disable-gpu --screenshot http://localhost