[AWS] - 우분투 서버 접속

배정규·2020년 7월 30일
0

aws

목록 보기
1/1

1. 서버접속: ssh -I junggyoo.pem ubuntu@3.129.89.206

2. 소스코드 가져오기: git clone

3. 프로젝트 디렉토리로 이동: ls -> cd 프로젝트디렉토리

4. 들어왔는지 확인: ls

5. node 설치:

1) curl -sL https://deb.nodesource.com/setup_10.x | sudo bash -
2) sudo apt-get install nodejs

6. node 설치 확인: node -v

7. npm 설치 확인: npm -v

8. 프로젝트 디펜던시 설치: npm install

9. 빌드 설치: npm run build

10. 빌드 설치 확인: ls -l

11. node express 설치: npm install express --save

(프로젝트 디렉토리 위치로 이동해서 설치해야됨 )

12. 서버 소스 코드 입력:

  • vi server.js
  • 서버 코드 입력
const http = require("http");
const express = require("express");
const path = require("path");

const app = express();

const port = 8080;

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}`);
});
  • 밑에서 두번째 줄에 있는 app.listen prot를 내 EC2 port 번호로 변경(나는 8000)
  • 저장 shift + : -> wq

13. server.js 확인: ls

14. 서버 연결: node server.js

15. app listening at 8000 떠야됨

16. 브라우져에 퍼블릭 ip 입력 3.129.89.206 하면 붐!

17. 서버 띄워놓기(프로젝트 디렉토리에서): node server.js &

서버 꺼도 계쏙 접속 가능

profile
Seize the day

0개의 댓글