GithubHelp home page GithubHelp logo

aws-nodejs-deploy's Introduction

Deploy Nodejs project to Amazon EC2 with Github Actions

After successfully connecting github to remote server follow this commands

Step 1: Update Package Repositories

Run the following command to update your package repositories:

sudo apt update

Step 2: Install Node.js

Install Node.js using the following command:

sudo apt-get install -y nodejs

Step 3: Install Nginx

Install Nginx to act as a reverse proxy for your Node.js application:

sudo apt-get install -y nginx

Step 4: Install PM2

Install PM2 globally to manage your Node.js application:

sudo npm i -g pm2

Step 5: Configure Nginx

Navigate to the Nginx sites-available directory and open the default configuration file for editing:

cd /etc/nginx/sites-available
sudo nano default

Inside the Nginx configuration file, add the following block to configure the reverse proxy for your API:

location /api {
    rewrite ^\/api\/(.*)$ /api/$1 break;
    proxy_pass http://localhost:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

Step 6: Restart Nginx

After making changes to the Nginx configuration, restart Nginx to apply the changes:

sudo systemctl restart nginx

Step 7: Start Your Node.js Application with PM2

Navigate to your project directory and start your Node.js application using PM2. Replace server.js with the actual filename of your Node.js application:

cd /path/to/your/app
pm2 start server.js --name=Backend

Step 8: Restart Your Node.js Application with PM2 (Optional)

If you need to restart your Node.js application managed by PM2, you can use the following command:

pm2 restart Backend

These steps should help you set up a Node.js backend API with Nginx and PM2 on your Debian-based Linux system. Make sure to customize the paths and filenames according to your specific project.

aws-nodejs-deploy's People

Contributors

satyam4484 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.