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

278
Vistas
Nginx - my 2nd nodes js app cannot listen to the new configured port

I've got 2 node apps in my Nginx with pm2. I had one in cluster mode, and now i started one in fork mode and 1 instance. I want 1 to listen to :3000 and the other to :4000. I've got the following configuration in my nginx.conf:

server {
listen 443 ssl;
listen [::]:443 ssl ipv6only=on;

ssl_certificate /path_to.key;
ssl_certificate_key /path_to.key;

server_name sub.domain.com;

location / {
    proxy_http_version 1.1;
    proxy_set_header Connection "";
    proxy_pass http://localhost:3000;
}

location /blog {
    rewrite /blog(.*)$ /$1 break;
    proxy_http_version 1.1;
    proxy_pass http://localhost:4000;
    proxy_set_header Connection "";
}

}

Then my simple node.js app looks like:

var express = require('express');
var http = require('http');
var bodyParser = require('body-parser');

var app = express();

var port = 4000;

app.use(function(req, res, next) { //allow cross origin requests
    res.set('Access-Control-Allow-Origin', "*");
    res.set('Access-Control-Allow-Methods', 'GET,OPTIONS,POST,PUT,DELETE');
    res.set('Access-Control-Allow-Headers', 'X-Requested-With,content-type,accept, content-type, x-parse-application-id, x-parse-rest-api-key, x-parse-session-token');
    res.set('Access-Control-Allow-Credentials', true);
    next();
});

app.use(bodyParser.json({limit: '50mb', type:'application/json'}));
app.use(bodyParser.urlencoded({limit: '50mb', extended: true, parameterLimit:100000,type:'application/x-www-form-urlencoding'}));

app.get('/',function(req, res) {
    res.status(200).send('Good. Serving.');
});

var theServer = http.createServer(app);

theServer.listen(port, function() {
    console.log('My 2nd, in fork mode, app is running on port ' + port + '.');
    process.send('ready');
});

So i was expecting that hitting sub.domain.com/blog or maybe directly to the 4000 port to get the response res.status(200).send('Good. Serving.');

I always use service nginx restart to restart the service with the new configurations.

Also in PM2 apps list i see my app online in fork mode etc. Am i missing something here?

Note: i normally see anything regarding my 1st app that listens to 3000.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Finally the issue was fixed. Be careful which .conf file you are editing. i was editing a .conf file outside of /etc/nginx and of course that is the reason of not working..

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