You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# EC2 인스턴스 생성 및 접속# 1. 프리티어 지원하는 우분투 등 기본 설정으로 생성, 키페어(.pem) 다운로드# 2. 탄력적 IP 생성 및 인스턴스와 연결: 안 하면 IP가 계속 바뀜# 3. 터미널에서 .pem이 있는 경로로 이동 후 아래 명령어 실행
ssh -i "<your pem key name>.pem" ubuntu@<your IPv4 Public IP># 인스턴스에 서버 설치 및 실행# 1. nodejs, npm 설치
sudo apt update
sudo apt install nodejs
sudo apt install npm
# 2. 깃 클론
git clone <your repository url># 3. 필요한 모듈 설치
npm install --only=prod
# 4. 여러 필요한 설정 후 node로 실행
node index.js
# EC2 인바운드 규칙 설정# EC2 -> 보안 그룹 -> 인바운드 규칙 편집# -> HTTPS, HTTP 추가, 웹 서버를 사용하지 않으면 개방할 서버 포트번호 추가# EC2 프록시 웹 서버 설치 및 실행 - nginx 사용# 1. nginx 설치
sudo apt install -y nginx
# -> 인스턴스 IP로 접속해서 welcome to nginx가 뜨는 지 확인!# 2. 폴더 이동cd /etc/nginx # -> '\'가 아님!# 3. 파일 수정
sudo vim sites-available/<FILE_NAME># 파일 내부에 작성# http 경우
server {
listen 80;
server_name <SERVER_PUBLIC_IP>;
charset utf-8;
location / {
proxy_pass http://localhost:<WEB_APP_PORT>;
}
}
# https 경우: nginx에 ssl 등록 후에 하기!
server {
listen 443 ssl;
server_name <DOMAIN_NAME>;
ssl_certificate /etc/letsencrypt/live/<DOMAIN_NAME>/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/<DOMAIN_NAME>/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
charset utf-8;
location / {
proxy_pass http://localhost:<WEB_APP_PORT>;
}
}
# 4. 심볼릭 링크 생성
sudo ln -s /etc/nginx/sites-available/<FILE_NAME> sites-enabled/<FILE_NAME># 뒤에 경로는 상관 없지만, 앞에 경로는 절대경로여야 함
ll sites-enabled # <FILE_NAME>이 파란색으로 뜨는 지 확인# 5. nginx 재시작
sudo service nginx restart
# 6. 서버 프로그램 디렉토리로 돌아가서 노드 실행cd~/<Nodejs-directory>
node src/index.js
# -> 브라우저에서 인스턴스 아이피로 접속한 후 테스트 해보기!# 터미널을 꺼도 서버가 실행되도록 하려면# 1. forever 또는 pm2 설치
sudo npm install -g forever 또는 pm2
# 2-1.
foever start -c node src/index.js
끄려면 forever list로 uid확인 후 forever stop <uid># 2-2.
pm2 start src/index.js
끄려면 pm2 kill 다시 시작은 pm2 restart src/index.js
# -> pm2를 많이 사용하는 추세라고 한다# 주의! ec2 cors 정책에 의해 access-allow-origin이 항상 wildcard(*)라 # cookie와 같이 credential이 필요한 것은 사용 불가# 토큰 저장할 때 쿠키 대신 localStorage를 활용하자.# https 통신이 가능하다면 쿠키를 사용해도 됨.# https 응답을 위한 SSL 등록 방법# 1. https://certbot.eff.org/instructions?ws=nginx&os=ubuntufocal# -> 여기서 해당하는 os와 웹서버로 검색한 후 지시에 따르자# 2. route53도메인에 레코드 추가: A, CAA 레코드 추가# https://docs.aws.amazon.com/ko_kr/Route53/latest/DeveloperGuide/resource-record-sets-creating.html# 3. nginx 재시작할 때 이미 http, https포트를 누가 쓰고 있다는 에러가 뜨면# https://happist.com/573788/%EC%9B%B9%EC%84%9C%EB%B2%84-%EC%97%90%EB%9F%AC-emerg-bind-to-443-failed-98-address-already-in-use
sudo fuser -k 80/tcp sudo fuser -k 443/tcp
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
2021년에 작성한 내용이고, 노드 서버 기반이라 참고만 하면 좋을 것 같습니다!
Beta Was this translation helpful? Give feedback.
All reactions