简体   繁体   English

从外部浏览器访问我的 AWS EC2 服务器 index.html

[英]Access my AWS EC2 server index.html from external browser

I've been setting up an AWS EC2 server this week, and I'm almost there with what I want to do.这周我一直在设置 AWS EC2 服务器,我几乎已经完成了我想做的事情。 But opening up as a web server is proving to be a stumbling block.但事实证明,作为 Web 服务器开放是一个绊脚石。

MY SETUP我的设置

I have an AWS EC2 instance running Red Hat EL7.我有一个运行 Red Hat EL7 的 AWS EC2 实例。

I have an Apache server running on my instance:我的实例上运行着一个 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

It seems to be listening on port 80:它似乎在监听 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   

I added inbound rules to the "launch-wizard-1" security group (which is shown as the security group for the instance) for port 80 (HTTP) and 443 (HTTPS) with sources of "0.0.0.0/0" and "::/0"我将入站规则添加到端口 80 (HTTP) 和 443 (HTTPS) 的“launch-wizard-1”安全组(显示为实例的安全组),来源为“0.0.0.0/0”和“ ::/0"

And finally, for testing my setup, I created an index.html file in my document root (/var/www/html):最后,为了测试我的设置,我在文档根目录 (/var/www/html) 中创建了一个 index.html 文件:

<html>
<h1>TEST!</h1>
</html>

THE PROBLEM问题

From my chrome browser on my computer, when I try to hit:从我电脑上的 chrome 浏览器中,当我尝试点击:

http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com/index.html http://ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com/index.html

I just get:我只是得到:

This page isn’t working
ec2-18-xxx-xxx-xx.us-east-2.compute.amazonaws.com didn’t send any data.
ERR_EMPTY_RESPONSE

(I get the same when I hit one of my domain names which I've set up on there, which is what I'm really trying to do of course!) (当我点击我在那里设置的一个域名时,我得到了同样的结果,这当然是我真正想要做的!)

I've tried connecting from Chrome on 2 different computers, and from Safari on my phone ("Safari cannot open the page because it could not connect to the server")我试过从 2 台不同计算机上的 Chrome 连接,以及从我手机上的 Safari 连接(“Safari 无法打开页面,因为它无法连接到服务器”)

CHECKS I'VE PERFORMED我做过的检查

I don't believe I have any server firewall preventing this:我不相信我有任何服务器防火墙阻止这种情况:

[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   

Testing with telnet from a terminal session on my mac, port 80 appears to be open.从我的 mac 上的终端会话使用 telnet 进行测试,端口 80 似乎是打开的。 Firstly using the IPv2 Public IP:首先使用 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.

and using the Public DNS (IPv4):并使用公共 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.

And again, the same goes for my domain names - telnet to port 80 shows "Connected".同样,我的域名也是如此——telnet 到端口 80 显示“已连接”。

- Is the fact that the "foreign host" closes the connection immediately significant? - “外国主机”立即关闭连接这一事实是否重要? Should it stay open if everything is working as it should?如果一切正常,它是否应该保持开放状态?

Running curl on the host correctly returns my simple index.html file:在主机上正确运行 curl 会返回我的简单 index.html 文件:

[ec2-user@ip-172-xx-xx-xx ~]$ curl localhost
<html>
<h1>TEST!</h1>
</html>

However, running a curl on my local computer - to the server - returns:但是,在我的本地计算机上运行 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

I also tested the webserver "internally" by running google chrome (headless) on the server to create a screenshot, downloaded to my local computer and it shows TEST.我还通过在服务器上运行 google chrome(无头)来“内部”测试网络服务器以创建屏幕截图,下载到我的本地计算机并显示 TEST。 (ie: its working): (即:它的工作原理):

google-chrome-stable --headless --disable-gpu --screenshot     http://localhost

One more thing to add - when I attempt the hit the webserver from my local machine, nothing shows in the webserver logs (error_log or access_log) on the server.要添加的另一件事 - 当我尝试从本地计算机访问网络服务器时,服务器上的网络服务器日志(error_log 或 access_log)中没有显示任何内容。

So, my opinion is that the web server is up and running, works locally, but is not working correctly for anything coming from "outside".因此,我的意见是 Web 服务器已启动并正在运行,在本地工作,但对于来自“外部”的任何内容都无法正常工作。 I'm stumped now though.不过我现在很困惑。

Doh.呵呵。 I rebooted the instance and.. all working now!我重新启动了实例并且......现在一切正常!

22 years working with computers and it took me 22 hrs to resort to a reboot.使用计算机 22 年,我花了 22 小时才重新启动。 Fool!傻子!

  1. Connect to your EC2 instance using ssh on terminalterminal上使用ssh连接到您的EC2 instance
  2. Install python if not installed如果没有安装python ,请安装
  3. Start a python server using nohup to continuously use the server使用nohup启动 python 服务器以持续使用服务器

    nohup python -m http.server &

  4. This usually open port 8000 , goto EC2 Security Group Make source anywhere or as needed.这通常打开端口8000 ,转到EC2 Security Groupanywhere或根据需要制作源代码。

在此处输入图像描述

  1. Navigate to the folder having index.html , file path will look like below导航到具有index.html的文件夹,文件路径如下所示

    http://ec2- - - .compute-1.amazonaws.com:8000/folder/website/ http://ec2- - - .compute-1.amazonaws.com:8000/folder/website/

You will be able to develop and see your changes as needed.您将能够根据需要开发和查看更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM