Apache and Node.JS on same port

After few tests, i got a small problem : i was using two system on my computer for testing, one on port 80 (apache + PHP) and the other on port 8080 (Node.JS with socket.io).

I just forgot the 8080 is locked on many system, so customers cannot have good experience because of that. Lucky I was, the apache system was able to do same stuff as Node.JS (but in long polling using PHP). I was of course needing to way to correct that because in such configuration, the PHP system where not so good as I explain before.

Apache in proxy mode

Here is a simple trick « hide » Node.JS behind Apache in proxy mode. On httpd.conf :

  • Load module : mod_proxy
  • Load module : mod_proxy_http

It was enough for me to have a proxy system on Apache. We will use this proxy system to forward port on specific url. Still on httpd.conf (or other file if you prefer clean install) :

Now if you go on ./node/ (DON’T forget / at the end), you will see Node.JS replying :
apache node.js proxy link

Of course on Node.JS side you can see :

var http = require("http");

http.createServer(function(request, response) {
	response.writeHead(200, {"Content-Type": "text/plain"});
	console.log("one client connect");
	response.write("Hello World from node");

Un commentaire

  1. Pingback: Apache and NodeJs on same port | NodeJs

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion /  Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion /  Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion /  Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion /  Changer )


Connexion à %s

%d blogueurs aiment cette page :