nodejs + apache = super easy integration

3,033 views
Skip to first unread message

Shimon Doodkin

unread,
Jun 3, 2011, 8:15:55 AM6/3/11
to nodejs
make an .htaccess file with:

RewriteEngine On
RewriteRule ^(.*)$ http://127.0.0.1:1337/$1 [P,L]
RewriteRule ^$ http://127.0.0.1:1337/ [P,L]
# see 'proxy|P' (force proxy) http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html


put it inside a folder and that's all!

by Shimon Doodkin

Arnout Kazemier

unread,
Jun 3, 2011, 8:20:29 AM6/3/11
to nod...@googlegroups.com
Imagine this, you just bought a brand new Ferrari and you want to take it for a spin on the highway.. So you go there.. But theres a big fat truck in front of you that only goes 50mph and there is no way to get passed it.

That is basically what you are doing if you put Apache (truck) in front of Node.js (Ferarri) This defeats one of the main purposes of using Node.js having a FAST evented machine.. Which does not allocate threads for requests.

Easy solutions are not always the best solutions

> --
> 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.
>

Ryan Gahl

unread,
Jun 3, 2011, 10:41:20 AM6/3/11
to nod...@googlegroups.com
More like you were driving the Ferrari and the truck opened up and a ramp came down and before you knew it the Ferrari was inside the truck. But hey, no biggie, you can still listen to the radio.

mscdex

unread,
Jun 3, 2011, 10:49:14 AM6/3/11
to nodejs
On Jun 3, 10:41 am, Ryan Gahl <ryan.g...@gmail.com> wrote:
> More like you were driving the Ferrari and the truck opened up and a ramp
> came down and before you knew it the Ferrari was inside the truck. But hey,
> no biggie, you can still listen to the radio.

You might not get very good reception inside the truck.

Onteria

unread,
Jun 3, 2011, 11:02:20 AM6/3/11
to nodejs
Oh how confused I was going from mode_rewrite rules to listening to
the radio inside a Ferrari. But yeah if you're just rerouting port 80
to port 1337 you can use iptables and kill the need for Apache
entirely. Either that or process.setuid to drop privileges after
binding to port 80 to keep from the nasty "running as root" issue.


Also the radio is currently playing:

http://www.youtube.com/watch?v=oHg5SJYRHA0

Regards,
Onteria

David Herron

unread,
Jun 3, 2011, 1:11:54 PM6/3/11
to nodejs
Okay.. so you're driving a ferrarri and stuck behind a truck - but
doesn't that just demonstrate the folly of owning a ferrari and
driving it on typical highways in todays cities? I mean, isn't it
silly to be owning such a car and driving it to the grocery store on
local streets?

Anyway.. back to Node and Apache..

Suppose you have a semi-managed VPS where you can install a Node
process to run a web site but you can't delete the Apache process
because it's doing other useful stuff like serving Drupal websites.
How do you get the Node based website to have a reasonable URL that
doesn't include the port number? This proxying approach is one way.
The other day I was looking at Nginx proxying to host a Node website
in a similar way. Perhaps Nginx is more palatable than Apache? There
are a few blog posts out there covering that combination.

An iptables approach might be lighter weight but I haven't a clue how
to do it ...

+ David Herron
http://davidherron.com

Shimon Doodkin

unread,
Jun 3, 2011, 2:37:14 PM6/3/11
to nodejs
Actually it works quite fast. faster then a APC cached php cgi page...

At least you can use nodejs.

for People who have a hosting system in place, like DirectAdmin.
It is a vast work to change ports and add reverse proxy...
with very little effort "at least they can listen to radio.."

I think it will be able to handle same load as Apache handles.
because people who have Apache also have a website that Apache can
handle.
maybe it will be able to handle even more load because because
it will not consume 9mb of php+mysql on each connection and will
respond faster

i have started by testing web sockets because i was curious. I have
figured out that mod_rewrite proxy does not support web-sockets,
I have tested there was no sensible difference in response times with
Apache in front 21ms vs node.js in front 18ms. with the example
res.end("hello world"); php did 83ms with just echo "hello world".
I have tested repetitive writes with for(var i=0;i<1000;i+
+)res.write('hello'); Apache did 119ms node.js did 93 ms. so anyway
write it is better to write response in a bulk.
i have tested long pulling and it works fine. setInterval(function()
{res.write('hello'+i+"\r\n");i++;},1000);

happy Ferrari radio listening...





On Jun 3, 3:15 pm, Shimon Doodkin <helpmep...@gmail.com> wrote:
> make an .htaccess file with:
>
> RewriteEngine On
> RewriteRule ^(.*)$http://127.0.0.1:1337/$1[P,L]
> RewriteRule ^$http://127.0.0.1:1337/[P,L]
> # see 'proxy|P' (force proxy)http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

mscdex

unread,
Jun 3, 2011, 2:42:56 PM6/3/11
to nodejs
On Jun 3, 1:11 pm, David Herron <da...@davidherron.com> wrote:
> Suppose you have a semi-managed VPS where you can install a Node
> process to run a web site but you can't delete the Apache process
> because it's doing other useful stuff like serving Drupal websites.
> How do you get the Node based website to have a reasonable URL that
> doesn't include the port number?  This proxying approach is one way.
> The other day I was looking at Nginx proxying to host a Node website
> in a similar way.  Perhaps Nginx is more palatable than Apache?  There
> are a few blog posts out there covering that combination.

You could also do the proxying in node itself (take a look at node-
http-proxy) :)

That way you don't have to worry about the problems introduced when
proxying from nginx (e.g. no http 1.1 support or websocket draft76
support).
Reply all
Reply to author
Forward
0 new messages