Build a development environment on AWS EC2 with CentOS7 + Nginx + pm2 + Nuxt.js

Build a development environment on AWS EC2 with CentOS7 + Nginx + pm2 + Nuxt.js

Introduction

Start-up companies do everything from the back end to the front end, but this time it's a development environment construction work!

I often stumbled, so I will leave it as a memo.

Development environment

Cloud: AWS EC2(t2.micro) OS: CentOS7 FW: Nuxt.js PM: pm2 Others: node.js, npm

setup

sudo yum update -y
sudo yum clean all

sudo yum install gcc-c++

sudo yum install nodejs npm
sudo npm install -g n

sudo n stable

sudo yum remove nodejs npm
sudo npm install -g nuxt
sudo npm install -g pm2

Creating a project

cd /var/www/html/
npx create-nuxt-app project name

create-nuxt-app v3.3.0
?  Generating Nuxt.js project in project name
? Project name:Project name
? Programming language: TypeScript
? Package manager: Npm
? UI framework: Vuetify.js
? Nuxt.js modules: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Linting tools: ESLint, Prettier
? Testing framework: Jest
? Rendering mode: Universal (SSR / SSG)
? Deployment target: Server (Node.js hosting)
? Development tools: (Press <space> to select, <a> to toggle all, <i> to invert selection)
? Version control system: Git

cd project name
npm install
npm install --save @nuxtjs/axios
npm install --save @nuxtjs/dotenv

Edit package.json

{
=== Omitted ===
  "scripts": {
    "dev": "nuxt-ts --hostname server name,
    "build": "nuxt-ts build",
    "start": "nuxt-ts start --hostname server name",
    "generate": "nuxt-ts generate",
    "lint:js": "eslint --ext .js,.vue --ignore-path .gitignore .",
    "lint": "npm run lint:js",
    "test": "jest"
  },
=== Omitted ===
}

Edit nuxt.config.js

import colors from 'vuetify/es5/util/colors'

export default {
=== Omitted ===
  // Modules (https://go.nuxtjs.dev/config-modules)
  modules: [
    "@nuxtjs/axios",
    '@nuxtjs/dotenv',
  ],
=== Omitted ===
  srcDir: "./",
}
npm run build

Nginx installation

See here

Install the latest version of Nginx stable on CentOS 7 (official repository)

Nginx settings

sudo vi /etc/nginx/conf.d/default.conf
upstream backend {
server server name:3000; #The server name is AWS EC2 Public IPv4 DNS
}

server {
    listen  80;
    listen  [::]:80;
    server_name server name; #The server name is AWS EC2 Public IPv4 DNS

    #charset koi8-r;
    charset utf-8;
    #access_log  /var/log/nginx/host.access.log  main;


    server_tokens off;

    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-Proto https;
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

        proxy_pass  http://backend;
        #proxy_redirect http:// https://;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        proxy_pass  http://backend;
        #proxy_redirect http:// https://;
    }
}

How to use

Nginx restart

sudo systemctl restart nginx

Start pm2

pm2 start --name "Project name" "npm -- run dev" // development

pm2 start --name "Project name" "npm -- run start" // production

Other commands for pm2

pm2 reload "Project name"
pm2 restart "Project name"
pm2 stop "Project name"
pm2 status
pm2 kill

Startup screen

** Vuetify.js ** is selected for the UI framework

PC

2020-10-01_17h08_56.png

Mobile

2020-10-01_17h12_03.png

At the end

There was not much information and I built it by repeating try & error Nginx reverse proxy? I was addicted to the setting of lol I would like to know if there is a better way

that's all

Recommended Posts

Build a development environment on AWS EC2 with CentOS7 + Nginx + pm2 + Nuxt.js
Build a Ruby on Rails development environment on AWS Cloud9
Build a CentOS 8 virtual environment on your Mac with VirtualBox
Build a PureScript development environment with Docker
Build a Java development environment on Mac
Build Java 8 development environment on AWS Cloud9
Build a Wordpress development environment with Docker
Build an environment with Docker on AWS
Build a development environment for Django + MySQL + nginx with Docker Compose
Steps to build a Ruby on Rails development environment with Vagrant
Build a WordPress development environment quickly with Docker
How to build a Ruby on Rails development environment with Docker (Rails 6.x)
Build a Laravel environment on an AWS instance
[Win10] Build a JSF development environment with NetBeans
How to build a Ruby on Rails development environment with Docker (Rails 5.x)
Build a Java development environment with VS Code
Build a development environment to create Ruby on Jets + React apps with Docker
[Note] Build a Python3 environment with Docker in EC2
[Environment construction] Build a Java development environment with VS Code!
Until you build a Nuxt.js development environment with Docker and touch it with VS Code
Build mate desktop environment on ec2 with terraform (Ubuntu 20.04LTS)
Build a Node.js environment with Docker
Build a Tomcat 8.5 environment with Pleiades 4.8
Build a Minecraft server on AWS
Build a XAMPP environment on Ubuntu
Build Unity development environment on docker
Build a Maven repository on AWS S3
[Ruby] Building a Ruby development environment on Ubuntu
Build a JMeter environment on your Mac
Build an Ultra96v2 development environment on Docker 1
Build a simple Docker + Django development environment
Build debug environment on container --Build local development environment for Rails tutorial with Docker-
Build a hot reload development environment with Docker-compose using Realize of Go
I tried to build a Firebase application development environment with Docker in 2020
[Copy and paste] Build a Laravel development environment with Docker Compose Part 2
Build a local development environment for Rails tutorials with Docker (Rails 6 + PostgreSQL + Webpack)
[Copy and paste] Build a Laravel development environment with Docker Compose Participation
Template: Build a Ruby / Rails development environment with a Docker container (Ubuntu version)
Template: Build a Ruby / Rails development environment with a Docker container (Mac version)
Build a development environment for Docker + Rails6 + Postgresql
Let's get started with Java-Create a development environment ②
Build a Doker-based development environment on Windows 10 Home 2020 ver. Part 1 Until WSL2-based Docker build
Let's get started with Java-Create a development environment ①
[Memo] Create a CentOS 8 environment easily with Docker
Build a Laravel / Docker environment with VSCode devcontainer
Environment construction command memo with Docker on AWS
[Java] Build Java development environment on Ubuntu & check execution
Build Apache / Tomcat development environment on Cent OS 7
Build a development environment for Docker, java, vscode
Build a Java runtime environment on Sakura VPS
How to build a Pytorch environment on Ubuntu
[First team development ②] Build an environment with Docker
Create a Spring Boot development environment with docker
Install Ubuntu 20.04 in virtual box on windows10 and build a development environment using docker
How to quit Docker for Mac and build a Docker development environment with Ubuntu + Vagrant
Install docker-compose on a Graviton 2 instance of AWS EC2
Create a Java development environment using jenv on Mac
[Rails] Nginx, Puma environment deployment & server study [AWS EC2]
Easily build a Vue.js environment with Docker + Vue CLI
Create a user with an empty password on CentOS7
CentOS8 + nginx1.18 + php-fpm7.4 + MariaDB10.5 + CodeIgniter4 development environment preparation memo