[英]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.