Backend hosted on EC2 refuses connection

0

I have launched EC2 instance and cloned my backend (Node.js) from GitHub, but i cannot connect to it neither via EC2 Console link (public IPv4 adress/public IPv4 DNS) nor via fetch from my front-end app (hosted on another service) i have the same error: ERR_CONNECTION_REFUSED. Instance is running, both status checks passed. Saw a similar question, unfortunately without a solution to the problem, it was advised to run a command wget http://localhost to check if application is working, and here's my output:

Resolving localhost (localhost)... 127.0.0.1
Connecting to localhost (localhost)|127.0.0.1|:80... failed: Connection refused.

.

It might be useful:

Network ACL has 2 inbound rules:

  • default (rule number *), which denies all traffic
  • i added rule with number 1, which allows all traffic

Also i have 2 security groups:

  • default, which i believe directs all traffic at itself? (it's source is self ID)
  • second group was generated on instance initialization and i added my own rules later, which allows all traffic (e.g. rule type HTTPS, protocol TCP, port range 443, source 0.0.0.0/0)
1回答
0

Access on localhost also appears to be failing.
Is the web server running in EC2?
Run the following command to find the process listening on port 80.

sudo lsof -i :80

If nothing is displayed, start the web server.

profile picture
エキスパート
回答済み 1年前
  • I'm not sure where exactly should i run this command. Tryed this in EC2 Instance Connect, nothing happend. Then i executed 'npm run start' and tryed again, and still nothing.

  • This command is executed on the EC2 that is used as the backend. How do you envision accessing the back-end application? If you use HTTP as the protocol, you would need to start a web server.

  • Well, this is exaxtly what i did.

  • If you run this command and nothing is displayed, it is likely that the web server is not running on EC2. We are not sure which web server you are using on your EC2, but we will describe an example for Nginx. The following is an example command to start Nginx. This command must be changed depending on the web server installed on your EC2.

    sudo systemctl start nginx
    sudo systemctl enable nginx
    
  • I'm not using Nginx/Apace/etc on my backend project. I only have Express and Cors libraries installed and configured to listen requests. Is this not enough? Should i try Nginx?

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ