Search code examples
node.jshttp-redirectnginxportnas

Nodejs express application on nginx linux server


I have created my first nodejs application with nodejs express. The server is

var express = require("express");
global.app = express();
require("src/app-modules/common/yamaha/yamaha.controller.api");
app.listen(8080, function() {
console.log("Listening on http://127.0.0.1:8080");
});

On windows development machine Is working. Now I try to publish this app on a Synology NAS. I access this application on url: //192.168.1.151/YamahaCtrl and I have a 404 error. Update 2: I discover what is realy the problem: how to configure the nginx server fromn Routes are defined on yamaha.controller.api like this one:

    app.get("/api/yamaha/getBasicInfo", function (req, res) {
        //do something
    });

I found a nodejs 8 beta package to install on NAS, and now I have nodejs version 8. But the error still remain.

So the nodejs app server is open on localhost:8080, but url access is http://192.168.1.151/YamahaCtrl, on 80.

That mean the problem is how to configure Virtual Host on NAS, and which port on node server I should use.

Update: The problem is: need to configure a redirect port on nginx server installed on Synology. I found this article: https://www.digitalocean.com/community/tutorials/how-to-set-up-a-node-js-application-for-production-on-ubuntu-14-04

and I create configuration file /etc/nginx/sites-available/default:

server {
listen 80;

server_name _;

location / {
    proxy_pass http://127.0.0.1:8080;
    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;
}

}

And still not working: the html files are accessible , but api is available on port 8080 only.


Solution

  • I figured out what the problem was: nodejs server is serving static files too, but my config for static files was wrong. For development was working, and that why I didn't know that is wrong.

    So it's no need to configure something on NAS :). To start nodejs application is enough.