cannot get node deployed on Ubuntu Lucid

47 views
Skip to first unread message

MilesTogoe

unread,
May 30, 2010, 6:25:21 PM5/30/10
to nod...@googlegroups.com
Node.js is only good as people can deploy it and so we would like to add to the documentation.   At the moment we cannot get node apps to render on an ubuntu production server with nginx - it seems nginx permissions are tricky.  Maybe someone can help?  here is our setup:

Ubuntu Lucid

/usr/bin/nginx => nginx installed with sugo apt-get install nginx

/etc/nginx/sites-enabled/app (actually in sites-available and sym linked)
server {
  listen   80;
  server_name  www.myapp.com;
             rewrite ^/(.*) http://myapp.com/$1 permanent;
  }
server {
  listen   80;
  server_name myapp.com;
  access_log /var/local/sites/app/log/access.log;
  error_log /var/local/sites/app/log/error.log;
  location / {
    root   /var/local/sites/app/;
            index  index.html;
    }
   }

/usr/local/bin/node  => node.js installed and compliled by sudo commands

added user "node" with admin rights

/etc/init/app.conf => script to fire node.js using user "node"
follows blog http://caolanmcmahon.com/
$> exec sudo -u node sh -c "/usr/local/bin/node  /var/local/app_main.js >> /var/log/myapp.log 2>&1"

with /var/sites/app/app_main.js (simple node app)
  => $> curl localhost:8080 is okay
  => browser www.myapp.com => 403 Forbidden

with /var/sites/app/index.html (simple html page)
  => renders fine

$> ls -l /var/sites/app => drwxrxr-x 5 node  1006  ....... app
$> ls -l /var/sites/app => -rw-r---r-- 1 node  1006  ....... app_main.js



ferenc vehmann

unread,
May 30, 2010, 7:08:52 PM5/30/10
to nod...@googlegroups.com
location configuration in nginx:
root /var/local/sites/app/;

This is where you have actually put all app:
$> ls -l /var/sites/app
here _local_ is missing.

this pont tho nginx doesn't know about your apps existence.
if you want to put your node app behind nginx you may experiment with
something like this:
..
location / {
proxy_pass localhost:8080
}
..

more info at the proxying examples
http://wiki.nginx.org/NginxConfiguration

f

> --
> You received this message because you are subscribed to the Google Groups
> "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com.
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en.
>

Scott Taylor

unread,
May 30, 2010, 10:53:53 PM5/30/10
to nod...@googlegroups.com

On May 30, 2010, at 6:25 PM, MilesTogoe wrote:

Node.js is only good as people can deploy it and so we would like to add to the documentation.   At the moment we cannot get node apps to render on an ubuntu production server with nginx - it seems nginx permissions are tricky.  Maybe someone can help?  here is our setup:

Ubuntu Lucid

/usr/bin/nginx => nginx installed with sugo apt-get install nginx

/etc/nginx/sites-enabled/app (actually in sites-available and sym linked)
server {
  listen   80;
  server_name  www.myapp.com;
             rewrite ^/(.*) http://myapp.com/$1 permanent;
  }
server {
  listen   80;
  server_name myapp.com;
  access_log /var/local/sites/app/log/access.log;
  error_log /var/local/sites/app/log/error.log;
  location / {
    root   /var/local/sites/app/;
            index  index.html;
    }
   }


You'll certainly need a proxy pass directive.  Here are the nginx docs:


Scott


Floby

unread,
May 31, 2010, 3:27:08 AM5/31/10
to nodejs
Yep, Proxy pass is the solution, worked fine for me. I followed some
if the instructions of this tutorial for Ruby & nginx but it's really
simple to apply the principle to nodejs
http://articles.slicehost.com/2009/3/13/ubuntu-intrepid-nginx-rails-and-thin

On 31 mai, 00:25, MilesTogoe <miles.to...@gmail.com> wrote:
> Node.js is only good as people can deploy it and so we would like to add
> to the documentation.   At the moment we cannot get node apps to render
> on an ubuntu production server with nginx - it seems nginx permissions
> are tricky.  Maybe someone can help?  here is our setup:
>
> Ubuntu Lucid
>
> /usr/bin/nginx => nginx installed with sugo apt-get install nginx
>
> /etc/nginx/sites-enabled/app (actually in sites-available and sym linked)
> server {
>    listen   80;
>    server_namewww.myapp.com;
>               rewrite ^/(.*)http://myapp.com/$1permanent;
>    }
> server {
>    listen   80;
>    server_name myapp.com;
>    access_log /var/local/sites/app/log/access.log;
>    error_log /var/local/sites/app/log/error.log;
>    location / {
>      root   /var/local/sites/app/;
>              index  index.html;
>      }
>     }
>
> /usr/local/bin/node  => node.js installed and compliled by sudo commands
>
> added user "node" with admin rights
>
> /etc/init/app.conf => script to fire node.js using user "node"
> follows bloghttp://caolanmcmahon.com/
> $> exec sudo -u node sh -c "/usr/local/bin/node  /var/local/app_main.js
>  >> /var/log/myapp.log 2>&1"
>
> with /var/sites/app/app_main.js (simple node app)
>    => $> curl localhost:8080 is okay
>    => browserwww.myapp.com=> 403 Forbidden

MilesTogoe

unread,
May 31, 2010, 5:05:22 AM5/31/10
to nod...@googlegroups.com, Floby
thks for help - proxy_pass works for us if we run the node.js sample
code. However if we run node-router it still fails on a 403 (I've
contacted Tim Caswell the node-router author)

On 05/31/2010 12:27 AM, Floby wrote:
> Yep, Proxy pass is the solution, worked fine for me. I followed some

> if the instructions of this tutorial for Ruby& nginx but it's really

Timothy Caswell

unread,
May 31, 2010, 8:29:28 AM5/31/10
to nod...@googlegroups.com
Very strange. 403 errors come from nginx not node-router. If you get a 403 I'm pretty sure it's never hitting the node app. Here is my nginx config for howtonode.org if it helps:

server {
listen 80;
server_name www.howtonode.org;
rewrite ^/(.*) http://howtonode.org permanent;
}

upstream backend {
server unix:/tmp/howtonode.sock;
}

server {
listen 80;
server_name howtonode.org;
location / {
server_tokens off;
add_header Server "Wheat (node.JS)";
proxy_pass http://backend;
}
}

If you're running the node app on a regular tcp port then you don't even need the separate upstream section, that's only required for unix sockets.

If you game me more specifics like what code you're using and exactly what http request your browser is making I can help more.

From you original post it looks like you're hitting localhost with curl, but the www.myapp.com in the browser. Try the domain name from curl too. When using virtual hosts, the Host header matters a lot to nginx.

MilesTogoe

unread,
May 31, 2010, 7:06:30 PM5/31/10
to nod...@googlegroups.com, Timothy Caswell
I realize node-router is not causing the 403, just that it is
redirecting to different pages and somewhere nginx is not getting to or
has wrong permissions.

thks Tim for the sample config.

If I run curl with the domain I get html with "301 Moved Permanently"

I don't understand where the add_header label comes from - our config is
below with the exception that we changed location / to using proxy_pass

MilesTogoe

unread,
Jun 1, 2010, 4:25:20 AM6/1/10
to nod...@googlegroups.com
On 05/31/2010 12:27 AM, Floby wrote:
> Yep, Proxy pass is the solution, worked fine for me. I followed some
> if the instructions of this tutorial for Ruby& nginx but it's really

tried to follow this and server is crashing - did you have changes to
this ?

also nginx config is set up to have a user "www-data", our node
scripts are set up to have user "node" - are there conflicts here ?
(we don't even have a user for www-data - maybe need to add one).

I really thing most of the problems track back to nginx and user
permissions - we had lots of trouble with permissions with sinatra and
eventually went back to apache with no problems. but I understand why
nginx is better for node - just need to get all these permission issues
resolved.

Reply all
Reply to author
Forward
0 new messages