Move Supabase files and scripts to archive, cleanup legacy code
This commit is contained in:
116
docs/WEB_SERVER_SETUP.md
Normal file
116
docs/WEB_SERVER_SETUP.md
Normal file
@@ -0,0 +1,116 @@
|
||||
# 웹 서버 설치 & 배포 가이드
|
||||
|
||||
## 1. Next.js 앱 단일 배포 (Ubuntu 22.04 + Nginx)
|
||||
|
||||
### 1.1 서버 준비
|
||||
```bash
|
||||
ssh your_user@your_server_ip
|
||||
# Node.js 18.x 설치
|
||||
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
|
||||
sudo apt-get install -y nodejs build-essential
|
||||
```
|
||||
|
||||
### 1.2 코드 클론
|
||||
```bash
|
||||
cd /var/www
|
||||
git clone https://github.com/your-org/your-repo.git my-nextjs
|
||||
cd my-nextjs
|
||||
```
|
||||
|
||||
### 1.3 의존성 설치 & 빌드
|
||||
```bash
|
||||
# npm
|
||||
npm install
|
||||
npm run build
|
||||
# 또는 yarn
|
||||
# yarn
|
||||
yarn build
|
||||
```
|
||||
|
||||
### 1.4 PM2로 서비스 등록
|
||||
```bash
|
||||
sudo npm install -g pm2
|
||||
pm2 start npm --name "my-nextjs" -- start
|
||||
pm2 save
|
||||
pm2 startup # 출력된 명령 복사 후 실행
|
||||
```
|
||||
|
||||
### 1.5 Nginx 리버스 프록시 설정
|
||||
```nginx
|
||||
# /etc/nginx/sites-available/my-nextjs.conf
|
||||
server {
|
||||
listen 80;
|
||||
server_name your.domain.com;
|
||||
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:3000;
|
||||
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;
|
||||
}
|
||||
}
|
||||
```
|
||||
```bash
|
||||
sudo ln -s /etc/nginx/sites-available/my-nextjs.conf /etc/nginx/sites-enabled/
|
||||
sudo nginx -t && sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
|
||||
## 2. 한 서버에 여러 사이트 호스팅
|
||||
|
||||
### 2.1 앱별 포트 분리
|
||||
- 디렉터리별 배치: `/var/www/site-alpha`, `/var/www/site-beta`
|
||||
- `package.json` start 스크립트에 포트 지정
|
||||
```jsonc
|
||||
"scripts": {
|
||||
"start": "next start -p 3000"
|
||||
}
|
||||
```
|
||||
|
||||
### 2.2 PM2로 프로세스 분리
|
||||
```bash
|
||||
# site-alpha
|
||||
cd /var/www/site-alpha
|
||||
npm install
|
||||
npm run build
|
||||
pm2 start npm --name site-alpha -- start
|
||||
|
||||
# site-beta
|
||||
cd /var/www/site-beta
|
||||
npm install
|
||||
npm run build
|
||||
pm2 start npm --name site-beta -- start
|
||||
|
||||
pm2 save
|
||||
pm2 startup
|
||||
```
|
||||
|
||||
### 2.3 Nginx 도메인별 서버블록 설정
|
||||
```nginx
|
||||
# /etc/nginx/sites-available/site-alpha.conf
|
||||
server {
|
||||
listen 80;
|
||||
server_name alpha.example.com;
|
||||
location / { proxy_pass http://127.0.0.1:3000; }
|
||||
}
|
||||
|
||||
# /etc/nginx/sites-available/site-beta.conf
|
||||
server {
|
||||
listen 80;
|
||||
server_name beta.example.com;
|
||||
location / { proxy_pass http://127.0.0.1:3001; }
|
||||
}
|
||||
```
|
||||
```bash
|
||||
sudo ln -s /etc/nginx/sites-available/{site-alpha.conf,site-beta.conf} /etc/nginx/sites-enabled/
|
||||
sudo nginx -t && sudo systemctl reload nginx
|
||||
```
|
||||
|
||||
### 2.4 (선택) SSL 자동 발급
|
||||
- Let's Encrypt + Certbot 설치
|
||||
```bash
|
||||
sudo apt-get install certbot python3-certbot-nginx
|
||||
sudo certbot --nginx -d alpha.example.com -d beta.example.com
|
||||
```
|
||||
Reference in New Issue
Block a user