-
Notifications
You must be signed in to change notification settings - Fork 1
/
nginx.conf
69 lines (56 loc) · 3.33 KB
/
nginx.conf
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
events {
worker_connections 1024;
}
http {
# 요청 속도 제한 초당 30개 이상 요청 시 503 에러
limit_req_zone $binary_remote_addr zone=restrict:10m rate=30r/s;
server {
listen 80; # 포트 번호
server_name 도메인.com; # 도메인 이름 ex:) eomjunsick.com api.eomjunsick.com
# 인증서용 경로
location /.well-known/acme-challenge/ {
allow all;
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri; # 모든 HTTP 요청을 HTTPS로 리디렉트
}
}
# 처음 발급 받을 때는 아래 전부 주석처리 후 certbot을 이용하여 인증서를 발급 받는다.
# 그 후 주석을 해제하고 다시 docker compose를 통해 nginx를 실행한다.
server {
listen 443 ssl;
server_name 도메인.com; # 도메인 이름 ex:) eomjunsick.com
ssl_certificate /etc/letsencrypt/live/도메인.com/fullchain.pem; # SSL 인증서 경로
ssl_certificate_key /etc/letsencrypt/live/도메인.com/privkey.pem; # 개인 키 파일 경로
access_log /var/log/nginx/access.log; # 로그 파일 경로
error_log /var/log/nginx/error.log; # 에러 로그 파일 경로
# 요청 속도 제한
limit_req zone=restrict burst=10 nodelay;
location / {
proxy_pass http://컨테이너서비스이름:3000; # http://[container_name]:[port]
proxy_set_header Host $host; # host
proxy_set_header X-Real-IP $remote_addr; # 클라이언트의 실제 IP 전송
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; # 클라이언트의 원본 IP 주소전송
proxy_set_header X-Forwarded-Proto $scheme; # 원래 요청의 프로토콜(http 또는 https)을 전송, 여기서는 사실상 https만 전달됨
proxy_cookie_path / "/; Secure"; # HTTPS 연결을 통해서만 쿠키 전송, 쿠키 관련해서 설정함
}
# SSE 연결을 위한 설정
location ~ ^/sse/.*$ {
proxy_pass http://컨테이너서비스이름:3000;
proxy_set_header Connection 'keep-alive'; # 'Connection' 헤더를 'keep-alive'로 설정 = 연결 유지
proxy_http_version 1.1; # http 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;
add_header Content-Type text/event-stream; # 응답 헤더에 'Content-Type: text/event-stream'을 추가하여 SSE 응답임을 명시
chunked_transfer_encoding off; # 청크 전송 인코딩을 비활성화 = 걍 데이터 쪼개서 안보내겠다는 뜻
proxy_read_timeout 3600s; # 프록시에서 클라이언트로의 읽기 시간 제한을 3600초(1시간)로 설정
proxy_buffering off; # 프록시 버퍼링 비활성화 = 데이터 즉시 전송
add_header Cache-Control no-cache; # 캐시 비사용 설정 = 이건 그냥 캐시때문에 문제 생길까봐 추가
proxy_cache_bypass $http_pragma; # 프록시 캐시를 비활성화 = 마찬가지
proxy_no_cache $http_pragma; # 프록시 캐시를 비활성화 = 마찬가지
}
}
}