Take the 2-minute tour ×

I have to put nodejs in port 80, but apache is already using it. How can I put both (nodejs and apache) on the same port 80? I need it because in my university all the ports are blocked except for PORT 80. (This is a realtime application with nodejs and socket.io (websockets) and in the other side a php application). Thanks a lot

share|improve this question
You can proxy node.js traffic through Apache. –  Douglas Jun 23 '12 at 19:39
@Douglas that is slow.. Then there is no purpose of using node.js because apache will slow it down. Better do it the other way around to be efficient. –  matejkramny Jul 21 '12 at 17:35
Hmm, I'd not heard of using node.js for performance before. For some reason, I'd assumed that he couldn't change the Apache setup, though I see now that the question doesn't say anything like that. –  Douglas Jul 22 '12 at 0:53
Nowadays I do it like this: Nginx:80 -> proxy depending on hostname -> node/apache/? from port 8000 onwards. –  matejkramny Sep 18 '13 at 17:48
add comment

6 Answers

up vote 5 down vote accepted

I've personally done this the other way round from @liammclennan. Some suggest that proxying through Apache defeats some of the performance and scalability advantages of Node (don't have experience myself as my server doesn't get that much traffic, but from @liammclennan's link: "Every request that comes in through Apache will cause an Apache thread to wait/block until the response is returned from your Node.js process.", which obviously doesn't mesh well with Node's architecture.)

I used node-http-proxy to set up a Node proxy server roughly as described in the first link (my Node proxy runs on port 80; Apache and my other Node services don't). Seems to be working well so far, though I have had occasional stability problems that I've 'solved' through checking the proxy's still running with a cron job (edit: it seems a lot more stable these days). The proxy's pretty lightweight, taking up about 30MB memory.

share|improve this answer
More popular, stable is to use NGinx. Even the (original but stopped developing) creator Ryan Dahl proposed this because node.js is still pretty young project. –  Alfred Jun 25 '12 at 14:43
@Alfred Fair enough. I understand that nginx is non-blocking, so wouldn't suffer the same issues there as Apache, and it certainly has a good reputation for speed. For me, Node seems like a good solution as it's pretty easy on memory and the software's already installed, but for bigger & busier sites it's probably the way to go right now. –  meloncholy Jun 25 '12 at 15:35
It sounds like an apache proxy would be ok for low traffic sites or for development, and when performance is needed later on you would go for a dedicated pure node.js server. –  snez Jan 9 at 1:20
@snez Sure, it should be fine, though in my experience just running a Node server (on a different port) is extremely easy for dev. That said, I have Node everywhere and don't use Apache much at all these days. –  meloncholy Jan 9 at 10:13
@meloncholy yes if you are getting paid to work exclusively on node projects :). Another solution for development is to run both apache and node on separate ports and proxy requests with pow (pow.cx) which is very easy. And with node on production I'd probably configure node cluster (rowanmanning.com/posts/node-cluster-and-express). –  snez Jan 10 at 10:48
add comment

I do this via node.js proxy..

Install http-proxy with npm or official page


var http = require('http'),
httpProxy = require('http-proxy'),
proxyServer = httpProxy.createServer ({
    hostnameOnly: true,
    router: {
        'domain.com':       '',
        'domain.co.uk':     '',
        '':        ''


This creates a node process listening to port 80, and forwarding requests for domains which go to :81,82,83 etc. I recommend running this with forever and adding an entry to init.d so your proxy is up in case system shuts down.

share|improve this answer
add comment

You can't. You have to run node.js on another port and then proxy requests through apache. You can do this using mod_proxy


share|improve this answer
add comment

I usually use haproxy as the front-end in situations like that and have that proxy to the appropriate backend server. (Though making your node.js process a proxy server is a valid approach too depending on your needs).

share|improve this answer
add comment

I found a cool gist Run apache and nodejs on port 80. did not try it yet but will do of course

share|improve this answer
add comment

I do this with .htaccess file

RewriteEngine On
RewriteRule ^$ [P,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

where XXXX is your port number. Put this file in your root directory

share|improve this answer
add comment

Your Answer


