Skip to content

Commit 4febcb4

Browse files
authored
[25.01.05 / TASK-91] Feature - 배포 위한 전체 app docker compose deploy 세팅 (#13)
* feature: nginx 추가, compose 완성 * modify: nginx 설정 파일 이름 변경 * feature: 전체 어플리케이션 배포 세팅, docker compose 포함, 타임존 이슈 핸들링 필요함 * modify: localhost 자체만 cors 에 추가 * modify: 미미한 수정, 볼륨 로그 디렉토리 가시성 증가
1 parent 5ec3e1e commit 4febcb4

File tree

7 files changed

+124
-7
lines changed

7 files changed

+124
-7
lines changed

.dockerignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
21
node_modules
32
.git
4-
.env
5-
dist
3+
.env

.env.sample

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PORT=8080
2-
ALLOWED_ORIGINS="http://localhost:3000,https://myapp.com"
2+
ALLOWED_ORIGINS="http://localhost,http://localhost:3000,https://myapp.com"
33
NODE_ENV="development"
44

55
# 토큰 단방향 암호화 전용 핵심 키

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ dist/
2222
Thumbs.db
2323

2424
# 로그 파일
25-
logs/
25+
logs/*
2626
*.log
2727
*.gz
2828
*.out

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ RUN pnpm install --prod --frozen-lockfile
3535
COPY --from=builder /usr/src/app/dist ./dist
3636
COPY ecosystem.config.js .
3737

38-
EXPOSE 3000
38+
EXPOSE 8080
3939

4040
CMD ["pm2-runtime", "start", "ecosystem.config.js"]

docker-compose.yml

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,55 @@
11
# docker-compose.yml
2+
name: velog-dashboard-v2-app
23
version: '3.9'
34

45
services:
5-
app:
6+
api:
67
build:
78
context: .
89
dockerfile: Dockerfile
10+
image: velog-dashboard-v2-api
11+
hostname: velog-dashboard-v2-api
912
container_name: velog-dashboard-v2-api
1013
ports:
1114
- "8080:8080"
15+
volumes:
16+
- ./logs/api:/usr/src/app/logs
1217
env_file:
1318
- .env
1419
environment:
1520
NODE_ENV: production
21+
TZ: Asia/Seoul
1622
restart: unless-stopped
23+
24+
fe:
25+
image: nuung/velog-dashboard-v2-fe:latest
26+
hostname: velog-dashboard-v2-fe
27+
container_name: velog-dashboard-v2-fe
28+
ports:
29+
- "3000:3000"
30+
volumes:
31+
- ./logs/fe:/usr/src/app/logs
32+
environment:
33+
NODE_ENV: production
34+
TZ: Asia/Seoul
35+
restart: unless-stopped
36+
depends_on:
37+
- api
38+
39+
nginx:
40+
image: nginx:alpine
41+
hostname: velog-dashboard-v2-nginx
42+
container_name: velog-dashboard-v2-nginx
43+
ports:
44+
- "80:80"
45+
- "443:443"
46+
volumes:
47+
- ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf
48+
- ./nginx/conf.d:/etc/nginx/conf.d
49+
- ./logs/nginx:/var/log/nginx
50+
environment:
51+
TZ: Asia/Seoul
52+
restart: unless-stopped
53+
depends_on:
54+
- api
55+
- fe
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
server {
2+
listen 80;
3+
server_name velog-dashboard-v2;
4+
5+
# fe
6+
location ^~ / {
7+
proxy_set_header Host $host;
8+
proxy_set_header X-Real-IP $remote_addr;
9+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
10+
proxy_set_header X-Forwarded-Proto $scheme;
11+
proxy_pass http://fe:3000;
12+
}
13+
14+
# api
15+
location ^~ /api/ {
16+
proxy_set_header Host $host;
17+
proxy_set_header X-Real-IP $remote_addr;
18+
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19+
proxy_set_header X-Forwarded-Proto $scheme;
20+
proxy_pass http://api:8080;
21+
}
22+
23+
# 404, 500 error 핸들링
24+
error_page 404 /404.html;
25+
location = /404.html {
26+
root /usr/share/nginx/error;
27+
}
28+
29+
error_page 500 502 503 504 /500.html;
30+
location = /500.html {
31+
root /usr/share/nginx/error;
32+
}
33+
}

nginx/conf/nginx.conf

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
user nginx;
2+
worker_processes 1;
3+
4+
pid /var/run/nginx.pid;
5+
6+
events {
7+
worker_connections 1024;
8+
}
9+
10+
http {
11+
include /etc/nginx/mime.types;
12+
default_type application/octet-stream;
13+
14+
log_format main '{"@time":"$time_iso8601",'
15+
'"IP":"$remote_addr",'
16+
'"Status":$status,'
17+
'"Method":"$request_method",'
18+
'"RequestTime":$request_time,'
19+
'"URI":"$request_uri",'
20+
'"QueryString":"$query_string",'
21+
'"SentSize":$bytes_sent,'
22+
'"UA":"$http_user_agent",'
23+
'"Session":"$http_authorization",'
24+
'"Referer":"$http_referer"}';
25+
26+
# charset koi8-r;
27+
access_log /var/log/nginx/access.log main;
28+
error_log /var/log/nginx/error.log warn;
29+
30+
# client send request size
31+
client_max_body_size 3G;
32+
33+
set_real_ip_from 127.0.0.1;
34+
real_ip_header X-Forwarded-For;
35+
36+
sendfile on;
37+
#tcp_nopush on;
38+
39+
keepalive_timeout 65;
40+
41+
#gzip on;
42+
43+
include /etc/nginx/conf.d/*.conf;
44+
45+
#security
46+
server_tokens off;
47+
}

0 commit comments

Comments
 (0)