-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnginx.conf
More file actions
128 lines (110 loc) · 4.63 KB
/
nginx.conf
File metadata and controls
128 lines (110 loc) · 4.63 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Logging
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log warn;
# Gzip compression
gzip on;
gzip_vary on;
gzip_min_length 1024;
gzip_types text/plain text/css text/xml text/javascript application/javascript application/json;
# Security headers
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
# DNS resolver for dynamic upstream resolution (internal Render DNS)
resolver ${RESOLVER} valid=30s;
resolver_timeout 5s;
server {
listen ${PORT};
server_name _;
# Health check endpoint for this proxy
location /health {
access_log off;
return 200 "nginx proxy healthy\n";
add_header Content-Type text/plain;
}
# Collect service routes - redirect without trailing slash
location = /collect/api {
return 301 /collect/api/;
}
location /collect/api/ {
set $collect_upstream http://${COLLECT_SERVICE_NAME}:10000;
rewrite ^/collect/api/(.*)$ /api/$1 break;
proxy_pass $collect_upstream;
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;
# Timeouts
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
}
# Backup upload / download on collect. POST /api/systems/backups
# receives a GPG blob up to 2 GB from appliances on slow uplinks;
# GET /api/systems/backups/:id streams the blob back out for
# restore. The defaults from the parent /collect/api/ (1 MB body
# cap, 30 s read timeout) would 413 and 504 both flows, so we
# match this sub-path first (^~) and override the relevant
# directives. request_buffering off keeps nginx's memory
# footprint flat while the body streams through to collect.
location ^~ /collect/api/systems/backups {
set $collect_upstream http://${COLLECT_SERVICE_NAME}:10000;
rewrite ^/collect/api/(.*)$ /api/$1 break;
proxy_pass $collect_upstream;
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;
client_max_body_size 2g;
client_body_timeout 600s;
proxy_request_buffering off;
proxy_connect_timeout 30s;
proxy_send_timeout 600s;
proxy_read_timeout 600s;
}
# Backend service routes - redirect without trailing slash
location = /backend/api {
return 301 /backend/api/;
}
location /backend/api/ {
set $backend_upstream http://${BACKEND_SERVICE_NAME}:10000;
rewrite ^/backend/api/(.*)$ /api/$1 break;
proxy_pass $backend_upstream;
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;
# Timeouts
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
}
# Frontend routes - everything else
location / {
set $frontend_upstream http://${FRONTEND_SERVICE_NAME}:10000;
proxy_pass $frontend_upstream;
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;
# Timeouts
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
}
}
}