Skip to content

Instantly share code, notes, and snippets.

@trandaison
Created January 13, 2022 12:03
Show Gist options
  • Select an option

  • Save trandaison/49c9c0df15a156fb7d905948ee70c136 to your computer and use it in GitHub Desktop.

Select an option

Save trandaison/49c9c0df15a156fb7d905948ee70c136 to your computer and use it in GitHub Desktop.

Revisions

  1. trandaison created this gist Jan 13, 2022.
    11 changes: 11 additions & 0 deletions check_ports.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # How to check if port is in use in

    ```sh
    sudo lsof -i -P -n | grep LISTEN
    sudo netstat -tulpn | grep LISTEN
    sudo ss -tulpn | grep LISTEN
    sudo lsof -i:22 ## see a specific port such as 22 ##
    sudo nmap -sTU -O IP-address-Here
    ```

    Reference: https://www.cyberciti.biz/faq/unix-linux-check-if-port-is-in-use-command/
    31 changes: 31 additions & 0 deletions ecosystem.config.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    module.exports = {
    apps: [
    {
    exec_mode: 'cluster',
    script: './server.js',
    args: 'start',
    // Options reference: https://pm2.io/doc/en/runtime/reference/ecosystem-file/
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '1G',
    env: {
    NODE_ENV: 'development',
    },
    env_production: {
    NODE_ENV: 'production',
    },
    },
    ],

    deploy: {
    dev: {
    user: 'dev',
    host: '18.222.247.184',
    repo: 'git@github.com:trandaison/trandaison.github.io.git',
    ref: 'origin/develop',
    path: '/home/dev/trandaison.github.io',
    'post-deploy': 'yarn && yarn build && pm2 start',
    },
    },
    };
    14 changes: 14 additions & 0 deletions git.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    # Install git

    ```sh
    # Perform a quick update on your instance:
    sudo yum update -y

    # Install git in your EC2 instance
    sudo yum install git -y

    # Check git version
    git version
    ```

    Reference: https://cloudaffaire.com/how-to-install-git-in-aws-ec2-instance/
    17 changes: 17 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    server {
    listen 80;
    server_name example.me;

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    auth_basic "Restricted Content";
    auth_basic_user_file /etc/nginx/.htpasswd;

    location / {
    proxy_pass http://localhost:3000;
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    }
    }
    48 changes: 48 additions & 0 deletions nginx.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    Reference: https://devcoops.com/install-nginx-on-aws-ec2-amazon-linux/

    ❌ Install nginx as root user, switch to root user before installing
    ```sh
    sudo su -

    ```

    # Enable and Install EPEL repo on AWS EC2 Amazon Linux 2 instance
    **Step 1.** Firstly, check if the EPEL repository is enabled:

    ```sh
    sudo amazon-linux-extras list | grep epel
    ```

    If you get an output like:
    ```
    24 epel available [ =7.11 =stable ]
    ```

    Then it means that you should enable it before installing Nginx.

    **Step 2.** To enable the EPEL repo on Amazon Linux 2 instance run:

    ```sh
    sudo amazon-linux-extras enable epel
    ```

    **Step 3.** Now you should be able to install the EPEL repo:
    ```sh
    sudo yum install epel-release
    ```

    # Install Nginx on AWS EC2 Amazon Linux 2 instance
    Step 1. Once the EPEL repo is installed you can install the Nginx latest version as well:
    ```sh
    sudo yum install nginx
    ```

    Step 2. Verify the installation:
    ```sh
    nginx -v
    ```

    Output:
    ```
    nginx version: nginx/1.20.1
    ```
    11 changes: 11 additions & 0 deletions nginx_basic_auth.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    # Basic Authen

    Example user: `userx` & password: `hmQE10_w`

    ```sh
    sudo sh -c "echo -n 'userx:' >> /etc/nginx/.htpasswd"
    sudo sh -c "openssl passwd hmQE10_w >> /etc/nginx/.htpasswd"
    cat /etc/nginx/.htpasswd
    ```

    Reference: https://www.digitalocean.com/community/tutorials/how-to-set-up-password-authentication-with-nginx-on-ubuntu-14-04
    21 changes: 21 additions & 0 deletions nginx_command.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    References: https://www.cyberciti.biz/faq/nginx-restart-ubuntu-linux-command/

    # Common Commands

    ```sh
    sudo systemctl start nginx
    sudo systemctl stop nginx
    sudo systemctl restart nginx

    sudo service nginx start
    sudo service nginx stop
    sudo service nginx restart

    sudo /etc/init.d/nginx start
    sudo /etc/init.d/nginx stop
    sudo /etc/init.d/nginx restart

    nginx -t # Check syntax if OK before reloading
    nginx -T # Check syntax and print the output before reloading
    nginx -s reload # Reload
    ```
    29 changes: 29 additions & 0 deletions nvm_node.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    ❌ Exit root user before install nvm

    # Install NVM

    ```sh
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
    ```

    # Install Node

    ```sh
    nvm install v14.17.3
    ```

    # Verify node version

    ```sh
    node -v
    ```

    # Install pm2
    ```sh
    npm install pm2 -g
    ```

    # Make pm2 auto-boot at server restart
    ```sh
    pm2 startup
    ```
    7 changes: 7 additions & 0 deletions ssh_keygen.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    # Generating a new SSH key and adding it to the ssh-agent

    ```
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
    # or
    ssh-keygen -t ed25519 -C "your_email@example.com"
    ```