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

285
Visualizações
Nginx how to run server.js file (not html) always in some port?

I am new to nginx and I know how to run simple root /var/www/example.com if it has html, it will run. But what if I have Angular app, and I have to run server.js in order to get ssr working ?

  1. I can run it with node server.js , but the server will be busy and I cant write anything then.
  2. I tried to change path to my server.js , but it was an error.

How to achieve something similar to this :

  1. node server.js - it would run on my selected port always and I could do anything else in the server without stopping node server.js command.
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

I suppose your intention is to deploy your app on a remote server, so this is what you need.

  1. Run node server.js locally continuously. To do this you can use pm2 which is installed using yarn on npm. Make sure you install it globally:

    npm install pm2 -g
    

    then navigate to your root folder and run your app using

    pm2 start server.js
    

    Your app is now daemonized, monitored and kept alive forever.

  2. Now we head to nginx. you will need to make edits to the config file by the name default in this location: /etc/nginx/sites-enabled

    sudo nano /etc/nginx/sites-enabled/default
    

    Now look for the closing tag of:

    server {
    
    
    } #this is its closing tag
    
  3. Add a proxy before the closing tag to direct all traffic from port 80 to your app ...

    say for example my server.js app is running on port 3000 locally, i will add this code so that the file looks like this:

    server{
    
        #a bunch of code that was preexisting.......
    
        location / {
            proxy_pass http://localhost:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        }
    
    }
    

At least this would give some insights to what you are after.... hope it helps.

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