Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

287
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda