Initial commit: 용산 공중케이블 주민 안전 협의회 홈페이지

- Next.js 16 App Router + TypeScript + Tailwind CSS 4
- Prisma/SQLite 기반 공지사항·자료실·관리자·문의/제보
- 네이버 블로그 RSS 최신 글 5개 노출
- OCI 운영 배포 스크립트 및 문서
This commit is contained in:
user01
2026-10-26 00:52:53 +09:00
commit 46bc36a1f5
88 changed files with 11750 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
# 운영 서버(/srv/yonggong)에서 실행하는 백업 스크립트.
# DB는 SQLite 백업 API로, 첨부파일은 tar로 보관하고 14일이 지난 백업은 지웁니다.
set -euo pipefail
ROOT=/srv/yonggong
STAMP=$(date +%Y%m%d-%H%M%S)
DEST="$ROOT/backups"
mkdir -p "$DEST"
# 서비스 중에도 안전한 SQLite 온라인 백업
python3 - "$ROOT/data/prod.db" "$DEST/db-$STAMP.db" <<'PY'
import sqlite3, sys
src, dst = sys.argv[1], sys.argv[2]
with sqlite3.connect(src) as s, sqlite3.connect(dst) as d:
s.backup(d)
PY
tar -czf "$DEST/uploads-$STAMP.tar.gz" -C "$ROOT/storage" uploads
find "$DEST" -type f -mtime +14 -delete
echo "[$(date -Is)] backup ok: db-$STAMP.db, uploads-$STAMP.tar.gz"
+88
View File
@@ -0,0 +1,88 @@
# saftyovhcable.kr — Next.js(yonggong) 리버스 프록시
# 레거시 정적 자산(/addMarker.html, /res/, /blogload.js)은 /var/www/html 에서 계속 서비스합니다.
# /etc/nginx/sites-available/saftyovhcable.kr
# 한글 도메인(용공협.kr)은 퓨니코드로 같은 server 블록에서 함께 처리합니다.
server {
listen 80;
listen [::]:80;
server_name saftyovhcable.kr xn--ob0bs83a9mfulcsua52c2xubym.xn--3e0b707e;
location ^~ /.well-known/acme-challenge/ {
root /var/www/html;
}
location / {
return 301 https://saftyovhcable.kr$request_uri;
}
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name saftyovhcable.kr xn--ob0bs83a9mfulcsua52c2xubym.xn--3e0b707e;
root /var/www/html;
index index.html;
ssl_certificate /etc/letsencrypt/live/saftyovhcable.kr/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/saftyovhcable.kr/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
client_max_body_size 60m;
client_body_timeout 120s;
# HTTPS 전용 (인증서 자동 갱신 검증 완료)
add_header Strict-Transport-Security "max-age=31536000" always;
# --- 레거시 지도/정적 자산 ---
location = /addMarker.html {
try_files $uri =404;
}
location ^~ /res/ {
try_files $uri =404;
expires 7d;
access_log off;
}
location = /blogload.js {
try_files $uri =404;
}
location ^~ /.well-known/acme-challenge/ {
root /var/www/html;
}
# 짧은 주소 / 옛 정적 페이지
location = /index.html { return 301 /; }
location = /index.htm { return 301 /; }
location = /news { return 301 /news/notice; }
location = /board { return 301 /news/notice; }
# --- Next.js 정적 자산 (캐시 헤더는 앱이 직접 설정) ---
location /_next/static/ {
proxy_pass http://yonggong_app;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
access_log off;
}
# --- 애플리케이션 ---
location / {
proxy_pass http://yonggong_app;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "";
proxy_read_timeout 120s;
proxy_send_timeout 120s;
}
}
+6
View File
@@ -0,0 +1,6 @@
# saftyovhcable.kr Next.js 앱 업스트림 (systemd: yonggong.service)
# /etc/nginx/conf.d/yonggong-upstream.conf
upstream yonggong_app {
server 127.0.0.1:3000;
keepalive 32;
}
+65
View File
@@ -0,0 +1,65 @@
#!/usr/bin/env bash
# 로컬 PC에서 실행: 빌드한 산출물만 운영 서버로 업로드합니다.
# (서버 RAM이 1GB뿐이므로 서버에서 next build를 돌리지 않습니다.)
#
# ./deploy/publish.sh # 빌드 + 업로드 + 재시작
# SKIP_BUILD=1 ./deploy/publish.sh # 이미 빌드된 산출물만 업로드
#
# 환경변수로 덮어쓸 수 있습니다: HOST, SSH_KEY, REMOTE_STAGE
set -euo pipefail
HOST="${HOST:-ubuntu@134.185.113.7}"
SSH_KEY="${SSH_KEY:-$HOME/Workspace/YSOVHCable_Project/Server/SSH/oci_web/ssh-key-2025-01-10-2.key}"
REMOTE_STAGE="${REMOTE_STAGE:-/home/ubuntu/yonggong-deploy}"
APP_DIR="/srv/yonggong/app"
SITE_URL="${SITE_URL:-https://saftyovhcable.kr}"
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$ROOT"
log() { printf '\n== %s\n' "$*"; }
log "1/6 빌드"
if [ "${SKIP_BUILD:-0}" != "1" ]; then
# NEXT_PUBLIC_* 값은 빌드 시 임베드되므로, 로컬 .env 값이 아니라 운영 값을 강제합니다.
export NEXT_PUBLIC_SITE_URL="${NEXT_PUBLIC_SITE_URL:-https://saftyovhcable.kr}"
export NEXT_PUBLIC_LEGACY_MAP_URL="${NEXT_PUBLIC_LEGACY_MAP_URL:-https://saftyovhcable.kr/addMarker.html}"
echo "NEXT_PUBLIC_SITE_URL=$NEXT_PUBLIC_SITE_URL"
npm run build
fi
test -f .next/standalone/server.js || { echo "standalone 산출물이 없습니다. npm run build 를 확인하세요."; exit 1; }
log "2/6 산출물 스테이징"
STAGE="$ROOT/.deploy/stage"
rm -rf "$STAGE"
mkdir -p "$STAGE"
cp -a .next/standalone/. "$STAGE/"
mkdir -p "$STAGE/.next"
cp -a .next/static "$STAGE/.next/static"
cp -a public "$STAGE/public"
rm -f "$STAGE/.env" "$STAGE"/.env.* # 환경변수는 서버의 /srv/yonggong/.env.production 사용
du -sh "$STAGE"
SSH_OPTS=(-i "$SSH_KEY" -o BatchMode=yes -o StrictHostKeyChecking=accept-new)
log "3/6 업로드 ($HOST:$REMOTE_STAGE)"
ssh "${SSH_OPTS[@]}" "$HOST" "mkdir -p '$REMOTE_STAGE' && rm -rf '$REMOTE_STAGE/app'"
rsync -az --delete -e "ssh ${SSH_OPTS[*]}" "$STAGE/" "$HOST:$REMOTE_STAGE/app/"
log "4/6 서버 반영 (데이터/첨부파일은 보존)"
ssh "${SSH_OPTS[@]}" "$HOST" "bash -s" <<EOF
set -euo pipefail
sudo -n rm -rf '$APP_DIR'
sudo -n mkdir -p '$APP_DIR'
sudo -n cp -a '$REMOTE_STAGE/app/.' '$APP_DIR/'
sudo -n chown -R yonggong:yonggong '$APP_DIR'
EOF
log "5/6 서비스 재시작"
ssh "${SSH_OPTS[@]}" "$HOST" "sudo -n systemctl restart yonggong && sleep 3 && sudo -n systemctl is-active yonggong"
log "6/6 상태 확인"
ssh "${SSH_OPTS[@]}" "$HOST" "curl -fsS -m 10 http://127.0.0.1:3000/api/health"
printf '\n'
curl -fsS -m 15 -o /dev/null -w "site: %{http_code}\n" "$SITE_URL/"
printf '배포 완료: %s\n' "$SITE_URL"
+32
View File
@@ -0,0 +1,32 @@
[Unit]
Description=Yonggong (saftyovhcable.kr) Next.js site
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=yonggong
Group=yonggong
WorkingDirectory=/srv/yonggong/app
EnvironmentFile=/srv/yonggong/.env.production
Environment=NODE_ENV=production
Environment=HOSTNAME=127.0.0.1
Environment=PORT=3000
Environment=NEXT_TELEMETRY_DISABLED=1
ExecStart=/usr/bin/node server.js
Restart=always
RestartSec=3
StandardOutput=journal
StandardError=journal
SyslogIdentifier=yonggong
# 보안 강화: 앱이 쓸 수 있는 경로만 열어 둡니다.
NoNewPrivileges=true
PrivateTmp=true
ProtectSystem=full
ProtectHome=true
ReadWritePaths=/srv/yonggong/data /srv/yonggong/storage
UMask=0027
[Install]
WantedBy=multi-user.target