【发布时间】:2023-10-15 00:59:01
【问题描述】:
我正在尝试使用 Nginx 在 Ubuntu 16 上托管此 Github repository。但我收到 502 bad request 错误。为了部署 express js 应用程序,我遵循了这个Digital Ocean tutorial。我已经在主目录中克隆了 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 端口的解决方案之一。这是我的本地主机端口报告:
谁能帮我找出导致错误的问题出在哪里?提前致谢。
【问题讨论】:
-
您确定根是
/home/ubuntu/blockchain-demo/routes;而不是/home/ubuntu/blockchain-demo;? -
routes文件夹中有一个index.js文件。因此,我指向那个文件夹。但在那之后,我将根目录更改为 home/ubuntu/blockchain-demo 文件夹,app.js 文件所在的位置。但我和之前一样收到 502 错误。
-
@MuminurRahman 你发现了吗?
-
不,我想不通。
标签: node.js express nginx ubuntu-16.04 pm2