簡體   English   中英

AWS EC2 無法訪問我的 ec2 公共域,嘗試了許多 web 解決方案都沒有用

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

我不認為這是一個非常常見的問題,我只是問這個問題,因為我已經使用我將在下面解釋的方法啟動了一些 ec2 實例並且我成功了,也許 EC2 立即更改了一些內容以通過 HTTP 連接它使用公共 dns。這是我一直執行的步驟,但我不知道為什么它不再起作用了。

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

1 - 設置默認安全組,為每個流量打開

安全組

2 - 將 IAM 策略添加到此 ec2,如下所示 IAM function

在此處輸入圖像描述

3 - 訪問SSH並配置nginx,我用putty可以進入實例。 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 - 從 github 克隆我的前端和后端存儲庫

5 - 構建生產並移動到 /var/www/html 所有前端 dist 文件

在此處輸入圖像描述

6 - 使用 pm2 啟動我的 node.js 服務器

在此處輸入圖像描述

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

如您所見,端口:80 正在被 nginx 監聽

伙計們,我不明白為什么我不能訪問這個實例的公共 dns,我做的一切都和我過去做的一樣,它一直在做這些步驟,使用 AWS EC2 ubuntu 20 實例發生了任何變化,讓我知道。 非常感謝,我正在努力解決這個問題。

嘗試解決它的最后步驟是檢查 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.>

但即使這樣做,也沒有解決問題:

sudo chmod -R 777 /var/www/html

當它在http (80)上運行時,您正在通過https (443)訪問該站點。 這是 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>

從瀏覽器: 地點

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM