Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs : EC2 인스턴스 셋업 총괄 (Git, Node, Nginx 까지) #18

Closed
unchaptered opened this issue Aug 23, 2022 · 0 comments
Closed
Assignees
Labels
documentation Improvements or additions to documentation

Comments

@unchaptered
Copy link
Member

unchaptered commented Aug 23, 2022

Nginx + Express 사용 설정

직전에 작성해 두었던 문서를 기반으로 제작되었습니다.

https://velog.io/@unchapterd/%EA%B5%AC%ED%98%84-Reverse-Proxy-Server
https://github.com/motd-5/motd-backend/blob/main/docs/technique/aws/Nginx%20%2B%20Express%20%EC%82%AC%EC%9A%A9%20%EC%84%A4%EC%A0%95.md

1단계 : AWS 설정

보안 그룹 생성 : 이름 가제 [project-security-group]

  • SSH 22 Anywhere IPv4
  • HTTP 80 Anywhere IPv4
  • 사용자 정의 TCP/IP 3000 Anywhere IPv4

EC2 인스턴스 생성 : 이름 가제 [project-server]

  1. 보안그룹 선택 : project-security-group
  2. SSH 발급 및 저장
  3. *.pem 키 권한 설정 참고글

Node 설치 및 기본설정

curl -s https://deb.nodesource.com/setup_16.x | sudo bash
sudo apt update
sudo apt install nodejs

sudo node -v
sudo npm -v
sudo git -v


sudo npm install pm2 -g
sudo npm ls -g


sudo git clone -b submain https://github.com/motd-5/motd-backend project
ls
cd /home/ubuntu/project
sudo npm ci

cd /home/ubuntu/project/src/sequelize
sudo mkdir seeders
sudo mkdir config

cd /home/ubuntu/project/src/sequelize/config
sudo nano config.json

-- Ctrl + O > Enter : 저장 -- Ctrl + X : 저장이 완료되었을 때는 바로 나와지고, 그렇지 않을 때는 아래 읽어보면 됨...

sequelize/config/config.json

{
    "development": {
        "username": "root",
        "password": "RDS-비밀번호",
        "database": "RDS-DB-이름",
        "host": "RDS-주소값",
        "dialect": "mysql"
    },
    "test": {
        "username": "root",
        "password": "RDS-비밀번호",
        "database": "database_test",
        "host": "RDS-주소값",
        "dialect": "mysql"
    },
    "production": {
        "username": "root",
        "password": "RDS-비밀번호",
        "database": "database_production",
        "host": "RDS-주소값",
        "dialect": "mysql"
    }
}

또한 다음의 파일을 만들어 주세요.

cd /home/ubuntu/project/src/middlewares/s3
sudo mkdir config

cd /home/ubuntu/project/src/middlewares/s3/config
sudo nano s3.config.json

middlewares/s3/config/s3.config.json

{
    "accessKeyId": "엑세스 키",
    "secretAccessKey": "시크릿 키",
    "region": "ap-northeast-2"
}

최종적으로 sequelize 를 설정해주세요.

cd /home/ubuntu/project/src/sequelize
sudo npx sequelize db:drop
sudo npx sequelize db:create
sudo npx sequelize db:migrate

준비가 종료되면 다음을 입력해주세요.

cd /home/ubuntu/project
npm run dev
pm2 start ./src/index.js

2단계 : Nginx

sudo apt install nginx
cd /etc/nginx/sites-enabled
sudo nano 도메인-주소
server {

	 listen 80;
   	 listen [::]:80;

	location / {
    		proxy_pass http://127.0.0.1:3000;
  	}

}
cd /etc/nginx
sudo nano nginx.conf
  1. # server_names_hash_bucket_size 64; 구문을 찾아서 # 주석 표시용 문구를 지워주세요
  2. include /etc/nginx/sites-enabled/*; 구문을 찾아서 include /etc/nginx/sites-enabled/도메인-주소; 로 변경해주세요.
@unchaptered unchaptered added the bug Something isn't working label Aug 23, 2022
@unchaptered unchaptered added documentation Improvements or additions to documentation and removed bug Something isn't working labels Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants