passenger nginx configuration

109 views
Skip to first unread message

fugee ohu

unread,
Apr 15, 2018, 10:19:55 PM4/15/18
to nodejs
My nginx conf has some ruby on rails web servers I'm trying to setup a node server for the first time my node server is located at /home/myusername/node_modules/peer/bin/peerjs where peerjs is a filename The suggested use is to have the server listen on port 9000, so in my nginx conf i've created a server with  passenger_app_type node;    passenger_startup_file peerjs; directives but what about the server root is supposed to be a path to my app's public directory It doesn't have a public directory, all it has is that path to the peerjs file so what should I put for root path?

server {
    listen 9000;
    server_name peerjs;

    # Tell Nginx and Passenger where your app's 'public' directory is
    #  root /usr/home/fugee/node_modules/peer;

    # Turn on Passenger
    passenger_enabled on;
    # Tell Passenger that your app is a Node.js app
    passenger_app_type node;
    passenger_startup_file peerjs;
}


Mikkel Wilson

unread,
Apr 17, 2018, 12:10:28 PM4/17/18
to nodejs
TL;DR - You probably don't need Nginx and you definitely don't need Passenger.

Node is different from Ruby in that it doesn't really need an HTTP proxy to sit in front of it (LinkedIn famously removed their front-end proxies a few years ago). When you run peerjs, it's starting an http server already. You can just hit the port it's listening to. Peerjs probably says what port it's listening to when it starts up. You can just use that for dev.

In production, this may vary a bit. If you're running in amazon, then an ELB/ALB will sit in front of your service and will direct traffic to this service:port. If not, you may want nginx for SSL termination or to split traffic on a path, but this is just a straight proxy_pass, not Passenger. Here's an excerpt from the nginx docs on setting up a simple proxy.

  server { # simple load balancing
    listen          80;
    server_name     big.server.com;
    access_log      logs/big.server.access.log main;

    location / {
      proxy_pass      http://big_server_com;
    }
  }

HTH,
Mikkel
Reply all
Reply to author
Forward
0 new messages