aws 사이트 로그인 후 '인스턴스 시작하기' 버튼을 클릭 해 ubuntu 프리티어 서비스를 선택해준다.
과금 되는 부분은 조심하면서🙀 서브넷 설정 + 우발적 종료방지 기능 check
태그 추가 클릭 후 키, 값 둘다 입력
폴더를 하나 만들어서 안전하게 저장하자.
재발급 안되니 이점 유의!
우분투 서버를 열게되면 다시 node도 깔아주고 프로젝트도 다시 clone해와야 한다. 그냥 콤퓨타 안에 멀티버스가 열렸다고 생각하면 된다.
ssh -i key이름.pem ubuntu@나의 aws ip주소
curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
sudo apt-get update
sudo apt-get install nodejs
git clone 프로젝트_repo_주소
cd 프로젝트_repo_주소
npm install
vi server.js
// insert 모드로 아래 코드 복사 붙여넣기
const http = require("http");
const express = require("express");
const path = require("path");
const app = express();
const port = 8000;
app.get("/ping", (req, res) => {
res.send("pong");
});
app.use(express.static(path.join(__dirname, "build")));
app.get("/*", (req, res) => {
res.set({
"Cache-Control": "no-cache, no-store, must-revalidate",
Pragma: "no-cache",
Date: Date.now()
});
res.sendFile(path.join(__dirname, "build", "index.html"));
});
http.createServer(app).listen(port, () => {
console.log(`app listening at ${port}`);
});
npm install express --save
서버를 간편하게 띄워주는 라이브러리 express
포트 설정은 아까 인스턴스 생성 때 써줬던 포트로 설정
해당 폴더에 모든 endpoint에 접속하게 되면 build 폴더 내에 index.html로 응답.
npm run build
node server.js &