
How to run Apache and Node.js together (the right way) - stagas
https://gist.github.com/754303
======
wwortiz
Isn't the advantage of proxying something like node that you can serve the
static files and a cache through the web server which works well for that?

~~~
aaronblohowiak
Apache doesn't handle large numbers of open/long-lasting connections like node
(or nginx) does. Further, it will completely fail to reverse-proxy websockets
(as will anything above layer 2 at this point.)

The best solution is to have your static files on a CDN.

------
bretthoerner
WHM cPanel? Seriously?

~~~
JonnieCache
A lot of us have no choice when at work.

~~~
steveklabnik
Yet you're able to run Node.js in production?

~~~
JonnieCache
I could if I wanted to. However if I disabled the control panel other people
would FREAK OUT because they would no longer be able to administer the more
simple sites without me around.

Edit: we have that parallels/ensim thing rather than cpanel but the point
stands.

~~~
steveklabnik
Gotcha. Never ceases to amaze me how some parts of the world work...

~~~
JonnieCache
I hope I haven't made it sound like we're disorganised or we don't have any
process. Its just that as lead developer my opinions are trusted, and if I am
convinced that using node.js on a slightly more experimental site is a good
idea, then people will believe me. I have some free reign to experiment, as
long as I don't make things more complicated for our core business. I think it
is a good balance.

As it happens I wouldnt use node.js in production right now, but thats not the
point.

~~~
steveklabnik
Yeah, no worries, I didn't mean to be condescending. That all sounds totally
reasonable... I just forget there are people that don't live on the command-
line sometimes.

------
ladon86
You should also do it this way with nginx if you want websockets to work. This
is because nginx proxy doesn't currently support http 1.1 or keep-alive.

------
EGreg
If you are designing a new site, and you are concerned about performance, I
would strongly suggest serving static (read: cacheable for a whole day) files
which include javascript which talks to Node on a port. Then, who cares what
the port is, as long as it works?

On the other hand, if you are integrating Node with existing code, say PHP,
then use TCP sockets behind a firewall, or Unix sockets for communication.

~~~
Zak
Listening on an unusual port can be a problem for users behind various
corporate, hotel and public wifi firewalls.

~~~
EGreg
do you mean it's a problem for browsers or for the servers?

------
EGreg
Why would anyone want to run Apache and Node.js? What is so special about
Apache? Use nginx.

And what do you mean by "with"? Just have Node listen on a different port,
what's the big deal about this?

~~~
tlrobinson
Most people don't like their public web servers to be on ports other than
80/443.

If you want the resources served by Node.js and another webserver to be on the
same domain/port you _need_ some sort of proxy configuration.

~~~
EGreg
Okay but I am assuming that most web servers are not run from users' private
computer networks, but from dedicated data centers, or somewhere in "the
cloud".

But yea I agree if you want node to listen on port 80 then you either forward
certain URLs to it (using nginx this is easy), or or you just get another IP
to point to the same machine, which is probably better.

------
Rauchg
In any case, if you only have one IP, it would be wiser to have Node.JS proxy
to Apache, not the other way around.

