简体   繁体   English

Node.js 在 EC2 上运行但无法在浏览器中使用 Nginx 访问的应用程序

[英]Node js Application running on EC2 but not accessible in browser using Nginx

I'm a newbie to Nginx. I cannot access my Node.js application that I deploy on AWS EC2 using Nginx reverse proxy.我是 Nginx 的新手。我无法访问我使用 Nginx 反向代理部署在 AWS EC2 上的 Node.js 应用程序。 If I do curl http://localhost:3000 I can see the application is running successfully on the server(I'm using pm2 for running node server).如果我执行curl http://localhost:3000我可以看到应用程序在服务器上成功运行(我正在使用 pm2 运行节点服务器)。 But when I try to access it in my browser or postman using public DNS I get the error This site can't be reached and the request gets timeout.但是当我尝试在我的浏览器或 postman 中使用 public DNS 访问它时,我收到错误This site can't be reached并且请求超时。 Here's my Nginx configuration (I have followed a number of tutorials for this)这是我的 Nginx 配置(我已经遵循了许多教程)

在此处输入图像描述

The configuration file is named nginx.conf and is in /etc/nginx/sites-enabled directory.配置文件名为 nginx.conf,位于 /etc/nginx/sites-enabled 目录中。 If I do sudo nginx -t it says syntax is ok and the test is successful.如果我执行sudo nginx -t它说语法没问题,测试成功。 Also I can see the Nginx is running using command sudo systemctl status nginx What could be the possible reason for this behaviour?我还可以看到 Nginx 正在使用命令sudo systemctl status nginx运行此行为的可能原因是什么?

I figured it out the problem wasn't with the Nginx configuration actually I needed to allow public access for port 80 on my ec2 instance which is blocked by default.我发现问题不在于 Nginx 配置,实际上我需要允许公共访问默认情况下被阻止的 ec2 实例上的端口 80。 I allowed port 80 and everything is working fine.我允许端口 80,一切正常。 Thisblog helped me.这个博客帮助了我。 Visit it for me details on how to enable port 80 for your ec2 instance.为我访问它,详细了解如何为您的 ec2 实例启用端口 80。

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

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