Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

405
Vistas
Run apache server and node on same port

I am using MAMP server and node js.

My issue is that I want to run apache server and node on the same port, but solutions online are quite complicated as it does not server much of the purpose, also I am new to Node. I need a simple solution where I can node on the port of apache server.

Code is below,

it works fine, as everything is running on different port but I want the 'server' to run on port 8888 where apache is running. Or some way for node to interact with apache

var express = require('express');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
var mysql = require('mysql');
var router = express.Router();

var connection = mysql.createConnection({
    host : 'localhost',
    user : 'root',
    password : 'root',
    database : 'db',
    port : '8889'
});

server.listen(8888); <----- ERROR
console.log('server running.......');

connection.connect(function(error){
    if(!!error) {
        console.log('error in db connection');
    } else {
        console.log('db connected');
    }
});

app.use('/*', router);

router.get('/*', function (req, res) {
    console.log('hello there...');
});
over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

I think the proper way to do this is to 'face' the Node service using Apache's Proxypass. This will forward a path to the node service running on a different port.

Adding the following to a your httpd.conf or under a vhost and restarting Apache should give you a working result

#I'm using 8890 for Node since your Apache runs on 8888 and DB is on 8889
ProxyPass /node/ http://localhost:8890/
ProxyPassReverse /node/ http://localhost:8890/

Navigating to http://localhost:8888/node/ will connect you to the node service running on port 8890.

over 4 years ago · Santiago Trujillo Denunciar

0

You can use http-proxy for that.

var http = require('http'),
httpProxy = require('http-proxy'),
proxyServer = httpProxy.createServer ({
    hostnameOnly: true,
    router: {
        '127.0.0.1':        '127.0.0.1:8080'
    }
});

proxyServer.listen(8888);

This will create a node process listening to port 8888, and forwarding requested domains to 8080.

over 4 years ago · Santiago Trujillo Denunciar

0

you will find many tutorials on this topic but here is a overview:

  • you need apache mod mod_proxy

  • basicly setup you need something like this, this link includes insturctions on how to set it up in a way, it will also forward your websockets (if you need that).

  • you will use somethink like, http://localhost:3005 where 3005 is the port nodejs runs on. (choose whatever port you like)

  • it might be usefull to add this port to you iptables to prevent direct access (without apache)

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda