0

Cannot reach my web service which is running on Nginx/CentOS 7. 502 Bad Gateway error occurs when I try to request. Developed with NodeJS. For more information I shared my configuration files.

Also codes work on local machine but not working on the server.

Server NodeJS version v10.10.0 Local NodeJS version v9.3.0

nginx config

upstream node_server {
server 127.0.0.1:5000 fail_timeout=0;
server 127.0.0.1:5001 fail_timeout=0;
}

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    index index.html index.htm;

    server_name alpha;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_redirect off;
        proxy_buffering off;
        proxy_pass http://node_server;
    }

    location /public/ {
        root /opt/app;
    }
}

Service file located at /etc/systemd/system/node-app-1.service

[Service]
ExecStart=/usr/bin/node /opt/app/app.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=node-app-1
User=root
Group=root
Environment=NODE_ENV=production PORT=5000

[Install]
WantedBy=multi-user.target

Error detail located in error.log file

2018/09/16 03:30:59 [error] 3102#0: *16 connect() failed (111: Connection refused) while connecting to upstream, client: <MYIPADDRESS>, server: alpha, request: "GET / HTTP/1.1", upstream: "<SERVERIPADDRESS>", host: "<SERVERIPADDRESS>"

I tried to run npm run start command inside my root folder and it worked fine.

http & https firewall enabled

Origin Server is up

Approximately I am searching this issue for 5-6 hours and could not find any solution to take a deep breath.

I could not find same question on the platform. If exist, please let me know and mark this question as duplicate.

jww
  • 97,681
  • 90
  • 411
  • 885
OwnurD
  • 195
  • 1
  • 3
  • 17
  • Possible duplicate of [Node.js connect only works on localhost](https://stackoverflow.com/q/14043926/608639). `server 127.0.0.1` say local machine only. If you want to listen on an external interface that others can connect to, then I believe you need to use an external IP address (or the "all interfaces" IP address). – jww Sep 16 '18 at 04:36
  • Actually similar configuration is working on another CentOs server. There are two differences between them. This service uses websocket and there is async await functions which responses 502 Bad gateway. Also I use express, there is no require of connect – OwnurD Sep 16 '18 at 17:49

0 Answers0