Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!