简体   繁体   English

AWS EC2 无法访问我的 ec2 公共域,尝试了许多 web 解决方案都没有用

[英]AWS EC2 can't access my ec2 public domain, tried many web solutions none worked

I don't this is a very common question, I'm only asking it because I've already started some ec2 instances using the method I'll explain bellow and I succed, maybe EC2 changed something the right away to connect it by HTTP using public dns. Here are the steps I've always done and I don't know why it isn't working anymore.我不认为这是一个非常常见的问题,我只是问这个问题,因为我已经使用我将在下面解释的方法启动了一些 ec2 实例并且我成功了,也许 EC2 立即更改了一些内容以通过 HTTP 连接它使用公共 dns。这是我一直执行的步骤,但我不知道为什么它不再起作用了。

public dns: ec2-23-22-52-143.compute-1.amazonaws.com公共 dns: ec2-23-22-52-143.compute-1.amazonaws.com

1 - Settup the default security group, that is oppened for every traffic 1 - 设置默认安全组,为每个流量打开

安全组

2 - Add IAM policity to this ec2, as you can see IAM function bellow 2 - 将 IAM 策略添加到此 ec2,如下所示 IAM function

在此处输入图像描述

3 - Access SSH and configure nginx, I used putty and could enter on the instance. 3 - 访问SSH并配置nginx,我用putty可以进入实例。 The configuration for nginx is /etc/nginx/sites-avaiable/default nginx的配置是/etc/nginx/sites-avaiable/default

## default nginx config

server {
  listen 80 default_server;
  server_name _;

  # front-end
  location / {
    root /var/www/html;
    try_files $uri /index.html;
  }

  # node api
  location /api/ {
    proxy_pass http://localhost:3000/;
  }
}

4 - Clone both my front-end and back-end repositories from github 4 - 从 github 克隆我的前端和后端存储库

5 - build production and move to /var/www/html all frontend dist files 5 - 构建生产并移动到 /var/www/html 所有前端 dist 文件

在此处输入图像描述

6 - Start my node.js server using pm2 6 - 使用 pm2 启动我的 node.js 服务器

在此处输入图像描述

7 - Start nginx 7 - 开始 nginx

sudo nginx -t

sudo systemctl start nginx

sudo.netstat -plant | grep 80

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      21159/nginx: master

As you can see the port:80 is being listening by nginx如您所见,端口:80 正在被 nginx 监听

Guys I have no ideia why I can't access the public dns of this instance, I made everything identical as I've done in the past, It has always been working doing these steps, anything has changed using AWS EC2 ubuntu 20 instance, let me know.伙计们,我不明白为什么我不能访问这个实例的公共 dns,我做的一切都和我过去做的一样,它一直在做这些步骤,使用 AWS EC2 ubuntu 20 实例发生了任何变化,让我知道。 Thanks a lot, I'm headaching trying to figure this out.非常感谢,我正在努力解决这个问题。

Last steps to try to solve it is check nginx logs尝试解决它的最后步骤是检查 nginx 日志

cd /var/log/nginx

2022/04/05 09:42:02 [error] 8216#8216: *1 directory index of "/var/www/html/" is forbidden, client: 103.178.236.40, server: _, request: "GET http://example.>

But even doing this, it has not solved the issue:但即使这样做,也没有解决问题:

sudo chmod -R 777 /var/www/html

You are accessing the site via https (443) while it's running on http (80) .当它在http (80)上运行时,您正在通过https (443)访问该站点。 Here is the result of curl.这是 curl 的结果。

root@MSI:~# curl -vk https://ec2-23-22-52-143.compute-1.amazonaws.com
* Rebuilt URL to: https://ec2-23-22-52-143.compute-1.amazonaws.com/
*   Trying 23.22.52.143...
* TCP_NODELAY set
* connect to 23.22.52.143 port 443 failed: Connection refused
* Failed to connect to ec2-23-22-52-143.compute-1.amazonaws.com port 443: Connection refused
* Closing connection 0
curl: (7) Failed to connect to ec2-23-22-52-143.compute-1.amazonaws.com port 443: Connection refused
root@MSI:~# curl -vk http://ec2-23-22-52-143.compute-1.amazonaws.com
* Rebuilt URL to: http://ec2-23-22-52-143.compute-1.amazonaws.com/
*   Trying 23.22.52.143...
* TCP_NODELAY set
* Connected to ec2-23-22-52-143.compute-1.amazonaws.com (23.22.52.143) port 80 (#0)
> GET / HTTP/1.1
> Host: ec2-23-22-52-143.compute-1.amazonaws.com
> User-Agent: curl/7.58.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: nginx/1.18.0 (Ubuntu)
< Date: Tue, 05 Apr 2022 13:02:08 GMT
< Content-Type: text/html
< Content-Length: 1676
< Last-Modified: Tue, 05 Apr 2022 09:54:30 GMT
< Connection: keep-alive
< ETag: "624c11d6-68c"
< Accept-Ranges: bytes
<
* Connection #0 to host ec2-23-22-52-143.compute-1.amazonaws.com left intact
<!DOCTYPE html><html class="bg-image" lang="en"><head><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="my icon" href="/assets/icone.ico" type="image/x-icon"><title>Lab301mktdigital</title><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.googleapis.com/css2?family=Comfortaa:wght@300;400;500;600;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Dancing+Script:wght@400;500;600;700&display=swap" rel="stylesheet"><link href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,400;0,500;0,600;0,700;0,800;0,900;1,400;1,500;1,600;1,700;1,800;1,900&display=swap" rel="stylesheet"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mdi/font@latest/css/materialdesignicons.min.css"><link rel="stylesheet" href="./assets/styles/general.css"><link href="/css/app.9ba0b389.css" rel="preload" as="style"><link href="/css/chunk-vendors.f754c4c0.css" rel="preload" as="style"><link href="/js/app.5380592f.js" rel="preload" as="script"><link href="/js/chunk-vendors.1ab5dd1a.js" rel="preload" as="script"><link href="/css/chunk-vendors.f754c4c0.css" rel="stylesheet"><link href="/css/app.9ba0b389.css" rel="stylesheet"></head><body><noscript><strong>We're sorry but freelancer-front-end doesn't work properly without JavaScript enabled. Please enable it to continue.</strong></noscript><div id="app"></div><script src="/js/chunk-vendors.1ab5dd1a.js"></script><script src="/js/app.5380592f.js"></script></body></html>

From browser:从浏览器: 地点

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

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