처음으로 React를 배포하게 되었다. 원래는 netlify를 통해 배포할 생각이었지만 팀원의 제안으로 인해 ec2로 배포환경을 바꾸게 되었다.
우선 apt를 통해 node.js와 npm, yarn을 설치해준다
yarn을 사용하지 않을 사람은 설치하지 않아도 된다
node -v
를 통해 버전을 확인할 수 있는데 node 버전이 10이상이여야 cra를 install할 수 있다.
여기서 꽤 많이 헤맸는데 공식문서에 답이 있었다 ㅎ..
NVM(node version manager)를 통해 node를 업데이트 하자!
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
혹은 wget을 통해 설치할 수 있다.
wget -q0- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
nvm ls-remote
나는 LTS버전인 14.17.5버전을 다운해 주었다.
nvm install 14.17.5
설치가 다되었으면 yarn을 통해 cra를 설치하였다.
rm /etc/nginx/sites-available/default
rm /etc/nginx/sites-enabled/default
기존에 들어가 있던 설정들을 지워주자!
> touch myapp.conf
> vi myapp.conf
server {
listen (원하는 포트입력);
location / {
root /(빌드파일 경로);
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
이렇게 설정하면 된다.
다음으로 sudo systemctl start nginx
를 통해 nginx를 시작해주면 된다!