카페24 가상호스팅에서 Node.js 개발 환경 구축하기 -2

inguk·2025년 4월 22일
0

안녕하세요! 오늘은 이전 포스팅에 이어서 사용하게될 bun과 pm2 , nginx와 ssl 인증서 설치까지 포스팅해보려고합니다

🌟 이 포스팅에서 다룰 내용
이번 포스팅에서는 실제 프로덕션 환경에서 필요한 모든 설정을 다룹니다:
Bun으로 더 빠른 JavaScript 실행환경 구축하기
PM2로 서버 무중단 운영하기
Nginx 웹서버 설정과 SSL 인증서 적용하기

1.사용된 플러그인

1. Bun

JavaScript/TypeScript 런타임
Node.js보다 빠른 실행 속도
내장 패키지 매니저 제공

2. PM2

Node.js 애플리케이션을 위한 프로세스 매니저
무중단 서비스 운영 가능
로그 관리 및 모니터링 기능 제공

3. Nginx

고성능 웹 서버
리버스 프록시 기능
로드 밸런싱 지원

4. SSL 인증서 설정

Let's Encrypt와 Certbot
무료 SSL 인증서 제공
자동 갱신 가능
보안 연결 지원

2. 플러그인 설치

1. Bun 설치 및 설정

# Bun 설치
curl -fsSL https://bun.sh/install | bash

# 환경변수 설정
export BUN_INSTALL="$HOME/.bun"
export PATH=$BUN_INSTALL/bin:$PATH

# 설치 확인
bun --version

2. PM2를 통한 프로세스 관리

# PM2 전역 설치
npm install -g pm2

# React 프로젝트 빌드 후 PM2로 서비스 시작
pm2 serve dist 3001 --name "cesium-front" --spa

# 주요 PM2 명령어
pm2 list                    # 프로세스 목록 확인
pm2 stop cesium-front       # 프로세스 중지
pm2 restart cesium-front    # 프로세스 재시작
pm2 delete cesium-front     # 프로세스 삭제
pm2 logs cesium-front       # 로그 확인
pm2 startup                 # 서버 재부팅시 자동 시작 설정
pm2 save                    # 현재 실행 중인 프로세스 목록 저장

3. Nginx 설치 및 설정

# Nginx 설치
sudo apt update
sudo apt install -y nginx

# Nginx 상태 확인
sudo systemctl status nginx

# 기본 설정 파일 백업
sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup

# 사이트 설정
sudo nano /etc/nginx/sites-available/your-domain.conf

# 설정 예시
server {
    listen 80;
    server_name your-domain.com;
    
    location / {
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

# 설정 활성화
sudo ln -s /etc/nginx/sites-available/your-domain.conf /etc/nginx/sites-enabled/
sudo rm -f /etc/nginx/sites-enabled/default

# 설정 테스트 및 재시작
sudo nginx -t
sudo systemctl restart nginx

4. SSL 인증서 설정

# Certbot 설치
sudo apt install -y certbot python3-certbot-nginx

# SSL 인증서 발급
sudo certbot --nginx -d your-domain.com

# 자동 갱신 테스트
sudo certbot renew --dry-run

# Nginx SSL 설정 예시
server {
    listen 443 ssl;
    server_name your-domain.com;
    
    ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem;
    
    # SSL 설정
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256;
    ssl_prefer_server_ciphers off;
    
    location / {
        proxy_pass http://localhost:3001;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }
}

지금까지 카페24 가상호스팅 서버에 개발 환경을 구축하는 방법을 기록과 함께 포스팅해봤습니다!

긴 글 읽어주셔서 감사합니다.

0개의 댓글