Using nginx with Node.js?

2,680 views
Skip to first unread message

Kay

unread,
Aug 19, 2011, 7:40:50 AM8/19/11
to nodejs
Hello everyone,

Is it necessary to install nginx in order to use Node.js? Or is it not
necessary, but recommended?

I'd like to start a new project using Node.js, but I am not very sure
about how to set it up. I've read several instructions, some of them
have not mentioned nginx at all, but some have recommended that one
should use nginx along with Node.js.

Could you enlighten me on the pros and cons of using nginx along with
Node.js, if it's optional to do so? Thanks.

Nicolas Chambrier

unread,
Aug 19, 2011, 7:46:01 AM8/19/11
to nod...@googlegroups.com

Short answer: nginx is faaaar better than node to render static files, but you'll need to recompile it if you use websockets (it cannot proxy ws as is)

> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> 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?hl=en

Nuno Job

unread,
Aug 19, 2011, 7:52:58 AM8/19/11
to nod...@googlegroups.com
Pedro did a screencast about it a while back: http://nodetuts.com/tutorials/25-nginx-and-nodejs.html#video

Александр Лозовюк

unread,
Aug 19, 2011, 7:54:15 AM8/19/11
to nod...@googlegroups.com
We are yousing nginx as front-end and proxy (http) to application in node.js. WebSocket-s have direct connectuon, without proxys

2011/8/19 Nicolas Chambrier <nah...@gmail.com>



--
C уважением, Александр Лозовюк
Alpha-Beta-Release Blog
http://abrdev.com

Joran Greef

unread,
Aug 19, 2011, 12:16:42 PM8/19/11
to nod...@googlegroups.com
Nginx cannot proxy HTTP 1.1 as far as I tried (though there may be plugins to change that).

What that means is that you can't do any "Transfer-Encoding: chunked" replies from Node.

Ultimately you can't do any sort of streaming out of Node if nginx is in front of it.

Seeing as you're starting out with Node, here's a good chance to rethink some things and simplify your deployment.

john.tiger

unread,
Aug 19, 2011, 3:10:38 PM8/19/11
to nod...@googlegroups.com

we do not use nginx with node but just use node itself as a front facing
proxy using node-http-proxy - we like the idea of less packages but we
haven't really seen it under big time loads yet but don't foresee any
problems. node-http-proxy has some good examples to follow - you can
try this first and see if it meets your needs. You can always fall
back and use Nginx.

Lou-adrien Fabre

unread,
Aug 20, 2011, 9:19:28 AM8/20/11
to nodejs
+1,
node-http-proxy worked fine for my till now, altough i'm not using it
in production, but nodjitsu use it in their production beta so it
should work fine. And as it was say you can still use nginx in
parrallele if you have a problem. But to me using Nginx is a bit
killing the interest of node : http 1.0 = no chunked/keep alive, plus
no web-sockets, etc.
I'd recommand using node-http-proxy and create a specific domain name
with a Nginx proxy for services that need over the years bullet-
proofness.

Kay

unread,
Aug 21, 2011, 4:03:39 AM8/21/11
to nodejs
Thanks for the tips regarding node-http-proxy, I think I am gonna
check this out =)

--
Gias Kay
http://blog.gantrithor.com/+

Hsu Ping Feng

unread,
Aug 22, 2011, 10:07:23 PM8/22/11
to nod...@googlegroups.com
There's a tcp proxy module for nginx:

It should be ok for websocket if you want to use nginx as a reverse proxy for node.


Fillano

2011/8/21 Kay <gsklee.of.p...@gmail.com>
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
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?hl=en



--
AUFKLÄRUNG ist der Ausgang des Menschen aus seiner selbstverschuldeten Unmündigkeit. Unmündigkeit ist das Unvermögen, sich seines Verstandes ohne Leitung eines anderen zu bedienen. Selbstverschuldet ist diese Unmündigkeit, wenn die Ursache derselben nicht am Mangel des Verstandes, sondern der Entschließung und des Mutes liegt, sich seiner ohne Leitung eines andern zu bedienen. Sapere aude! Habe Mut, dich deines eigenen Verstandes zu bedienen! ist also der Wahlspruch der Aufklärung.

Richard Marr

unread,
Aug 23, 2011, 4:00:23 AM8/23/11
to nod...@googlegroups.com
On 19 August 2011 12:40, Kay <gsklee.of.p...@gmail.com> wrote:
> Is it necessary to install nginx in order to use Node.js? Or is it not
> necessary, but recommended?

Depends. 

How big is your team? What's the lifespan of your app? It's much easier to find an Ops guy who knows Nginx well than it is to find someone who knows Node.js, so if you're anticipating this app being in production for long enough for an Ops guy to touch it then he'll be annoyed you used Node.js for something he'd rather do with a more familiar tool.

As an aside, if you're willing to learn Nginx then do so. It's more mature/stable, built specifically for the task, highly regarded, and there's a massive quantity of documentation and community blogs around it.




--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
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?hl=en



--
Richard Marr

Evgeny Bogdanov

unread,
Aug 29, 2011, 6:37:59 AM8/29/11
to nod...@googlegroups.com
Another way to go is to put haproxy in front
then redirect static files to nginx and the rest to node

see this post:
https://groups.google.com/forum/#!searchin/nodejs/evgeny$20bogdanov/nodejs/w0UCAech2LY/7YUJ_HcrS6kJ

Felix Halim

unread,
Oct 12, 2011, 3:59:30 AM10/12/11
to nod...@googlegroups.com
I saw one of Ryan Dahl's presentation that when node get matured
enough, we won't need nginx.

Is now a good time to drop nginx and run node alone? or should I wait?

If now is a good time, then what is the best way to run node on port
80 with non-root privilege?

I see several ways people do this on other web servers:
- run as root, then drop the privilege
- use iptables to redirect the port

Felix Halim

Matt

unread,
Oct 12, 2011, 8:01:21 AM10/12/11
to nod...@googlegroups.com
On 12 Oct 2011, at 03:59, Felix Halim <felix...@gmail.com> wrote:

> Is now a good time to drop nginx and run node alone? or should I wait?

I still like using a front end proxy server as it allows you to present a nice error page while you restart your app server (assuming you're only running one server with no load balancing).

> If now is a good time, then what is the best way to run node on port
> 80 with non-root privilege?
>
> I see several ways people do this on other web servers:
> - run as root, then drop the privilege
> - use iptables to redirect the port

If you're using cluster you just tell it the user to run as, and start it as root. It will drop the privileges for you. If you're not using cluster you probably should be :)

john.tiger

unread,
Oct 12, 2011, 9:46:00 AM10/12/11
to nod...@googlegroups.com
On 10/12/2011 01:59 AM, Felix Halim wrote:
> I saw one of Ryan Dahl's presentation that when node get matured
> enough, we won't need nginx.
>
> Is now a good time to drop nginx and run node alone? or should I wait?

Losers wait - winners take action but plan out a risk evaluation. Try
it on something not too critical and then step up. I'm pretty
conservative but at some point you just have to break some ground if you
want to move forward - there are a bunch of people using Node without
another front server and no one has posted that they tried it and it was
not up to par and they had to revert so that's an indication that the
water is pretty safe to step in - please post your experiences to build
the knowledge base.

Thomas Love

unread,
Oct 12, 2011, 11:14:15 AM10/12/11
to nodejs

On Oct 12, 9:59 am, Felix Halim <felix.ha...@gmail.com> wrote:
> I saw one of Ryan Dahl's presentation that when node get matured
> enough, we won't need nginx.
>
> Is now a good time to drop nginx and run node alone? or should I wait?
>

I'd say it's a good time to drop nginx when you expect a measurable
benefit to accrue from doing so.

Otherwise what's the point? Premature optimization and all that...

Even if you have a measurable benefit, it should outweigh the costs. I
think most of the costs are hard to quantify though, and will
materialize as maintenance and flexibility trouble down the line. For
this reason I'm personally in favour of maintaining separation of
function and having each component "doing one thing well". Node might
be a perfectly good webserver, but that's not its main strength. Nginx
on the other hand is a brilliant webserver. They complement each other.

john tigernassau

unread,
Oct 12, 2011, 2:40:37 PM10/12/11
to nod...@googlegroups.com


On Oct 12, 2011 9:14 AM, "Thomas Love" <tom...@gmail.com> wrote:
>
>
> On Oct 12, 9:59 am, Felix Halim <felix.ha...@gmail.com> wrote:
> > I saw one of Ryan Dahl's presentation that when node get matured
> > enough, we won't need nginx.
> >
> > Is now a good time to drop nginx and run node alone? or should I wait?
> >
>
> I'd say it's a good time to drop nginx when you expect a measurable
> benefit to accrue from doing so.
>
> Otherwise what's the point? Premature optimization and all that...
>
> Even if you have a measurable benefit, it should outweigh the costs. I

Oh, let me second that - i misread and did not realize you were already running behind nginx.   The golden rule still applies: if it is not broke don't fix it unless you really have to. 

But I will disagree with @Thomas - node is a web server, though perhaps with some different features and maybe not as good on some issues (some have posted that nginx serves static files faster but not sure about that) but if those are not critical then ....   And the less component interaction => the less complexity, the less maintenance, etc.    For us it is one less package to install and configure, and update

So pick a test project and try it out - i suggest you look at node-http-proxy

> think most of the costs are hard to quantify though, and will
> materialize as maintenance and flexibility trouble down the line. For
> this reason I'm personally in favour of maintaining separation of
> function and having each component "doing one thing well". Node might
> be a perfectly good webserver, but that's not its main strength. Nginx
> on the other hand is a brilliant webserver. They complement each other.
>

Dean Landolt

unread,
Oct 12, 2011, 2:50:38 PM10/12/11
to nod...@googlegroups.com
On Wed, Oct 12, 2011 at 2:40 PM, john tigernassau <john.tig...@gmail.com> wrote:


On Oct 12, 2011 9:14 AM, "Thomas Love" <tom...@gmail.com> wrote:
>
>
> On Oct 12, 9:59 am, Felix Halim <felix.ha...@gmail.com> wrote:
> > I saw one of Ryan Dahl's presentation that when node get matured
> > enough, we won't need nginx.
> >
> > Is now a good time to drop nginx and run node alone? or should I wait?
> >
>
> I'd say it's a good time to drop nginx when you expect a measurable
> benefit to accrue from doing so.
>
> Otherwise what's the point? Premature optimization and all that...
>
> Even if you have a measurable benefit, it should outweigh the costs. I

Oh, let me second that - i misread and did not realize you were already running behind nginx.   The golden rule still applies: if it is not broke don't fix it unless you really have to. 

But I will disagree with @Thomas - node is a web server, though perhaps with some different features and maybe not as good on some issues (some have posted that nginx serves static files faster but not sure about that) but if those are not critical then ....   And the less component interaction => the less complexity, the less maintenance, etc.    For us it is one less package to install and configure, and update

So pick a test project and try it out - i suggest you look at node-http-proxy


I completely agree with all this, but I would add that the biggest caveat to a public-facing node is the security question. It hasn't been poked and prodded like the "legacy" players have, nor has it undergone the kinds of code-audit colonoscopies (as far as I know, at least).

That's not to say it's a problem, just that you may want to make sure the test project you use to test a public-facing node is isolated from anything too sensitive (if you have anything like that). But sure, there's no better way for us to find out how battle-ready node is than to put it on the front lines and see how it fares.

Ryan Schmidt

unread,
Oct 14, 2011, 7:12:12 PM10/14/11
to nod...@googlegroups.com

On Oct 12, 2011, at 02:59, Felix Halim wrote:

> If now is a good time, then what is the best way to run node on port
> 80 with non-root privilege?
>
> I see several ways people do this on other web servers:
> - run as root, then drop the privilege

I was planning to follow this strategy to do that:

http://onteria.wordpress.com/2011/05/31/dropping-privileges-using-process-setuid-in-node-js/


David W. McKelvey

unread,
Oct 14, 2011, 7:40:34 PM10/14/11
to nod...@googlegroups.com
I use authbind to allow access to port 80 of a non-root user. Works quite well.

David
---

-- 
David W. McKelvey

Reply all
Reply to author
Forward
0 new messages