我正在尝试使用Nginx在Ubuntu 16上托管此Github repository。但是我收到502错误的请求错误。为了部署express js应用程序,我遵循了此Digital Ocean tutorial。我已经在主目录中克隆了仓库,并安装了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/"
我用Google搜索了,找到了不同的解决方案。建议的解决方案之一是检查localhost:3000端口。这是我的本地主机端口报告:
任何人都可以帮助我找出导致错误的问题在哪里吗?提前致谢。