Skip to content

πŸ“š A step-by-step guide for setting up a linux server with NodeJS, Nginx and Git Hook Listener.

Notifications You must be signed in to change notification settings

bn/aws-ec2-guide

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 

Repository files navigation

AWS EC2 Instructions

A step-by-step guide for setting up a linux server with NodeJS, Nginx and Git hook listener.

Summary
  1. Creating the AWS EC2 instance
  2. Connecting to server and installing NodeJS
  3. Nginx and configuration
  4. Git hook listener
  5. Author

1. Creating the AWS EC2 instance

You should have an AWS registration. They give a free year of VPS server! πŸ˜ƒ

  • Login into your AWS account and choose EC2 in AWS dashboard:

  • Click in the "Launch Instance" button:

  • Select Ubuntu Server

  • Choose "t2.micro" tier, click on "Review and Launch" button

  • Then click on "Launch" button, which will open a poup asking for a key pair creation. Choose "Create a new key pair", name it, download it and then click on "Launch instances".

  • Finally, your server will be initialized! Obs.: Copy and paste the "Public DNS" or "Public IP" in a separated document for further instructions! πŸ“

  • Next, you should open the some ports in order to expose your server to external requests from the internet. Click on the link close to "Security groups", from the previous picture. Then add the inbound request ports 80, 22 and 443, clicking on "Edit" button, as the follow image:

  • Now you are ready for connecting to your server! πŸ‘


2. Connecting to server and initializing it

I will be using bash commands (Mac or Linux). For Windows, check this out. So I think you should be fine... Please give me a feedback on this.

  1. Open terminal and connect via ssh to your server. Obs.: here we need the "Public DNS" or "Public IP" and the key pair file (.pem) mentioned before.

        $ chmod 400 [path to .pem file]
        $ ssh ubuntu@[your server ip or dns] -i [path to .pem file]
    

  2. Install NodeJS (in this example, version 6):

    	$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
    	$ sudo apt-get install -y nodejs
    
  3. Set npm path to user's home and install packages: PM2, Nodemon, Git:

        $ npm config set prefix ~/npm
    	$ export PATH="$PATH:$HOME/npm/bin"
    
    	$ npm install pm2 -g
    	$ pm2 startup       
    	    // If show "You have to run this command as root", run the given command!
    	
    	$ npm install nodemon -g
    	$ sudo apt install git
    
  4. Store your Git user credentials. This will prevent the login prompt when using Git commands.

        $ nano ~/.netrc
        
        // And add these lines:
        machine github.com (or bitbucket.org)
        login [YOUR_USER]
        password [YOUR_PASS]
        
        // Save it using: CTRL + o, ENTER
        // And exit using: CTRL + x, ENTER
    

3. Nginx

Here we will install Nginx, configure it to router external requests from port 80 (remember that we have open this port before?) to server's local port 3000, which could be a NodeJS application running in this port. We will setup a NodeJS application in next step.

  • First, install nginx:

        $ sudo apt-get update
        $ sudo apt-get install nginx
    
  • Then we need to edit the config default file in order to forward requests:

        $ sudo nano /etc/nginx/sites-available/default
        
        // In "server" block, put a # character at these lines:
        # root /usr/share/nginx/html;
        # index index.html index.htm;
        
        // Clear everything inside "location /" block , and set it like this
        location / {
                proxy_pass http://localhost:3000;           
        }
        
        // Save it using: CTRL + o, ENTER
        // And exit using: CTRL + x, ENTER
    

    It should look like this:

  • And reload Nginx with new configuration redirecting requests from port 80 (http) to local port 3000

        $ sudo service nginx restart
    

4. Git Hook Listener

This is a project that I have done in order to use the continuous deployment concept that automatizes the process of uploading project files to multiple servers and environments. This is a daily used component in the companies that I have worked.

Please continue by reading the step-by-step guide, like this one.


5. Author

Renan Caldas de Oliveira

About

πŸ“š A step-by-step guide for setting up a linux server with NodeJS, Nginx and Git Hook Listener.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published