-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnginx.conf
More file actions
75 lines (64 loc) · 2.66 KB
/
nginx.conf
File metadata and controls
75 lines (64 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
events {
# t3.micro에 맞게 연결 수 제한 (1024 -> 256, 메모리 절약)
worker_connections 256;
# Linux에서 고성능 I/O 이벤트 모델 사용
use epoll;
# 한 번에 여러 연결 수락 (성능 향상)
multi_accept on;
}
http {
# 기본 성능 최적화
sendfile on; # 커널에서 직접 파일 전송 (성능 향상)
tcp_nopush on; # 패킷 배칭으로 네트워크 효율성 향상
tcp_nodelay on; # 작은 패킷 지연 없이 전송
keepalive_timeout 30; # 연결 유지 시간 (60s -> 30s 로 줄여 메모리 절약)
keepalive_requests 100; # 한 연결당 최대 요청 수
# Gzip 압축 (대역폭 30-70% 절약)
gzip on;
gzip_vary on; # Vary: Accept-Encoding 헤더 추가
gzip_min_length 1000; # 1KB 이상 파일만 압축
gzip_types text/plain text/css application/json application/javascript text/xml application/xml;
upstream app {
server app:3000;
# 업스트림 연결 재사용 (2개 연결 유지)
keepalive 2;
}
server {
listen 80;
server_name daiily.site www.daiily.site;
return 301 https://$server_name$request_uri;
}
server {
# HTTPS 포트(443)에서 SSL 연결 수신
listen 443 ssl;
# 처리할 도메인명 지정 (메인 도메인 + www 서브도메인)
server_name daiily.site www.daiily.site;
# SSL 인증서 파일 경로 (공개키)
ssl_certificate /etc/nginx/ssl/cert.pem;
# SSL 개인키 파일 경로 (비밀키)
ssl_certificate_key /etc/nginx/ssl/key.pem;
# 정적 자산 캐싱 (1년 캐시, 서버 부하 감소)
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2)$ {
expires 1y;
add_header Cache-Control "public, immutable";
proxy_pass http://app;
proxy_http_version 1.1;
proxy_set_header Connection "";
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;
}
location / {
proxy_pass http://app;
# HTTP/1.1 사용으로 keepalive 활성화
proxy_http_version 1.1;
proxy_set_header Connection "";
# 필수 헤더 전달
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;
}
}
}