Setting up Node.js in nginx

Today I decided to test out Node.js (the trend in web tech) on nginx. Of course I googled it and found this link.

I already have nginx running on my server, so I did not have to install nginx again. Only pkgs that I needed were git-core and monit.

In the step 2: Packages at the site, it states:

apt-get install sudo vim-nox nginx ~~~

However, it needs to be this instead:

sudo apt-get install vim-nox nginx ~~~

In Step 3. once you get node.gif, from the current directory you need to cd to *node* directory.

*make* command took about 10 m.

*make install* threw out an error:

Cannot create folder ‘/usr/local/include/node/’ (original error: [Errno 13] Permission denied: ‘/usr/local/include/node/’)
make: *** [install] Error 1

So I had to *sudo make install* instead.

In the Step 4: Configure the Web Server. Since I am using port 80 as my own site, not proxy. So I changed the nginx conf file in a different way although all settings are very similar. I created another server setting that listens to port 8001 instead of 80 just for access to Node.js application from outside. By the way I have a file name as for my own site nginx conf file. Additional conf settings that I added to was:

upstream app_cluster_1 {
server {
listen 8001;
access_log /{my_site_directory}/log/node_access.log;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://app_cluster_1/;
proxy_redirect off;

Obviously I had to open port 8001 for my host.

When I run a node sample application, request from a browser to the app responds. So first step is success.

I will write about how I made the node app as daemon like service soon.

To be continued…

more references:


  • Miguel Espinoza

    Why did you want to use nginx? I believe node.js doesnt need another server as you can creAte one in it with only a few lines of code


    right node.js doesn’t need another server. However, node.js isn’t ready for replacing http server yet according to the creator of node.js and also nginx is primary http server for all of my sites. I only have one host and do not have additional to just host node.js. 😛

  • Miguel Espinoza

    Thanks for your reply :) much appreciated as I am starting a project on node.js as well, it will need to hold something between 1 and 400k simultaneous connections, now its clear to me that nginx is the right server for this scenario, Ive also been thinking of using Minix instead of a full-out OS, feels like it should give me more for my hardware, specially since the only processes in node.js will be logic operations, no database, no memcache, no static files, just web sockets telling something to each client

Leave a Reply

Your email address will not be published. Required fields are marked *