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

293
Vistas
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 Respuestas
Responde la pregunta

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 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