繁体   English   中英

使用 ExpressJS,Nginx 和 PM2 获取 502 Bad Gateway 错误

[英]Getting 502 Bad Gateway Error with ExpressJS, Nginx & PM2

我正在尝试使用 Nginx 在 Ubuntu 16 上托管此Github 存储库。但我收到 502 错误请求错误。 为了部署 express js 应用程序,我遵循了这个Digital Ocean 教程 我已经在主目录中克隆了 repo 并安装了 pm2。 我还使用pm2 start app.js启动了我的应用程序,它正在运行。 这是我的 pm2 状态: 在此处输入图像描述 在此处输入图像描述

我也按照提到的Digital Ocean教程配置了Nginx代理服务器。 我的配置文件(位置:/etc/nginx/sites-available/default)如下:

# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;

        #root /var/www/html;
        root /home/ubuntu/blockchain-demo/routes;

        # Add index.php to the list if you are using PHP
        index index.js index.html index.htm index.nginx-debian.html;

        server_name 54.255.173.175; #this is my public IP. I don't have domain.

        location / {
                proxy_pass http://127.0.0.1:3000;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection 'upgrade';
                proxy_set_header Host $host;
                proxy_cache_bypass $http_upgrade;
        }

Nginx错误日志如下:

2018/10/15 15:38:13 [error] 6283#6283: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 27.147.204.239, server: 54.255.173.175, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:3000/", host: "54.255.173.175"
2018/10/15 15:38:14 [error] 6283#6283: *5 connect() failed (111: Connection refused) while connecting to upstream, client: 27.147.204.239, server:54.255.173.175, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:3000/favicon.ico", host: "54.255.173.175", referrer:http://54.255.173.175/"

我用谷歌搜索并找到了不同的解决方案。 建议检查 localhost:3000 端口的解决方案之一。 这是我的本地主机端口报告: 在此处输入图像描述

谁能帮我找出导致错误的问题在哪里? 提前致谢。

请尝试 sudo pm2 start app.js

暂无
暂无

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

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