-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnginx-proxy.conf
More file actions
341 lines (280 loc) · 11.9 KB
/
Copy pathnginx-proxy.conf
File metadata and controls
341 lines (280 loc) · 11.9 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
events {
worker_connections 1024;
}
http {
# Rate limiting zones
limit_req_zone $binary_remote_addr zone=nominatim:10m rate=30r/m;
limit_req_zone $binary_remote_addr zone=tileserver_styles:10m rate=100r/s;
limit_req_zone $binary_remote_addr zone=osrm_route:10m rate=1r/s;
# Proxy cache configuration
proxy_cache_path /var/cache/nginx/tiles levels=1:2 keys_zone=tiles_cache:100m max_size=10g inactive=7d use_temp_path=off;
proxy_cache_path /var/cache/nginx/osrm levels=1:2 keys_zone=osrm_cache:50m max_size=1g inactive=1h use_temp_path=off;
# Security headers
add_header X-Frame-Options DENY always;
add_header X-Content-Type-Options nosniff always;
server_tokens off;
upstream nominatim_backend {
server nominatim:8080;
}
upstream tileserver_backend {
server tileserver-gl:8082;
}
upstream osrm_backend {
server osrm:8083;
}
upstream codepush_backend {
server codepush-server:3000;
}
# Nominatim proxy on port 8080
server {
listen 8080;
server_name localhost;
location / {
# Rate limiting: 30 requests per minute
limit_req zone=nominatim burst=5 nodelay;
limit_req_status 429;
# Rate limit headers
add_header X-RateLimit-Limit "30/minute" always;
proxy_pass http://nominatim_backend;
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;
# Nominatim specific settings
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
# Cache geocoding results briefly
proxy_cache osrm_cache;
proxy_cache_valid 200 5m;
proxy_cache_valid 404 1m;
proxy_cache_key $scheme$request_method$host$request_uri;
add_header X-Cache-Status $upstream_cache_status always;
}
}
# Tileserver proxy on port 8082
server {
listen 8082;
server_name localhost;
# High-frequency endpoints (styles, sprites, fonts)
location /styles/ {
# Rate limiting: 100 requests per second for styles
limit_req zone=tileserver_styles burst=50 nodelay;
limit_req_status 429;
# Rate limit headers
add_header X-RateLimit-Limit "100/second" always;
proxy_pass http://tileserver_backend;
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;
# Tileserver specific settings
proxy_connect_timeout 10s;
proxy_send_timeout 10s;
proxy_read_timeout 10s;
# Long-term caching for tiles - 1 week
proxy_cache tiles_cache;
proxy_cache_valid 200 7d;
proxy_cache_valid 404 1h;
proxy_cache_key $scheme$request_method$host$request_uri;
add_header X-Cache-Status $upstream_cache_status always;
# Cache control headers
add_header Cache-Control "public, max-age=604800" always; # 1 week
}
# Tile endpoints (z/x/y.png, z/x/y.pbf, etc.)
location ~ ^/.+/(\d+)/(\d+)/(\d+)\.(png|jpg|jpeg|webp|pbf)$ {
# More permissive rate limiting for individual tiles
limit_req zone=tileserver_styles burst=100 nodelay;
limit_req_status 429;
proxy_pass http://tileserver_backend;
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;
# Tileserver specific settings
proxy_connect_timeout 10s;
proxy_send_timeout 10s;
proxy_read_timeout 10s;
# Very long caching for individual tiles - 1 week
proxy_cache tiles_cache;
proxy_cache_valid 200 7d;
proxy_cache_valid 404 1h;
proxy_cache_key $scheme$request_method$host$request_uri;
add_header X-Cache-Status $upstream_cache_status always;
# Cache control headers
add_header Cache-Control "public, max-age=604800, immutable" always; # 1 week, immutable
}
# Other endpoints (metadata, fonts, sprites)
location / {
# Standard rate limiting for other endpoints
limit_req zone=tileserver_styles burst=20 nodelay;
limit_req_status 429;
proxy_pass http://tileserver_backend;
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;
# Tileserver specific settings
proxy_connect_timeout 10s;
proxy_send_timeout 10s;
proxy_read_timeout 10s;
# Medium-term caching for metadata
proxy_cache tiles_cache;
proxy_cache_valid 200 1d;
proxy_cache_valid 404 1h;
proxy_cache_key $scheme$request_method$host$request_uri;
add_header X-Cache-Status $upstream_cache_status always;
}
}
# OSRM proxy on port 8083
server {
listen 8083;
server_name localhost;
# Routing endpoints - very expensive operations
location /route/ {
# Strict rate limiting: 1 request per second per IP
limit_req zone=osrm_route burst=2 nodelay;
limit_req_status 429;
# Rate limit headers
add_header X-RateLimit-Limit "1/second" always;
proxy_pass http://osrm_backend;
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;
# OSRM specific settings
proxy_connect_timeout 10s;
proxy_send_timeout 10s;
proxy_read_timeout 30s;
# Cache routing responses
proxy_cache osrm_cache;
proxy_cache_valid 200 15m; # Cache successful routes for 15 minutes
proxy_cache_valid 404 5m; # Cache not found for 5 minutes
proxy_cache_key $scheme$request_method$host$request_uri;
add_header X-Cache-Status $upstream_cache_status always;
}
# Other OSRM endpoints (table, match, nearest, etc.)
location / {
# Slightly more permissive for non-routing endpoints
limit_req zone=osrm_route burst=5 delay=3;
limit_req_status 429;
# Rate limit headers
add_header X-RateLimit-Limit "1/second" always;
proxy_pass http://osrm_backend;
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;
# OSRM specific settings
proxy_connect_timeout 10s;
proxy_send_timeout 10s;
proxy_read_timeout 30s;
# Cache other responses
proxy_cache osrm_cache;
proxy_cache_valid 200 10m;
proxy_cache_valid 404 2m;
proxy_cache_key $scheme$request_method$host$request_uri;
add_header X-Cache-Status $upstream_cache_status always;
}
}
# CodePush API-only proxy on port 8084 (public access)
server {
listen 8084;
server_name localhost;
# Increase client body size for app bundles
client_max_body_size 100M;
# Block admin panel access - return 404 to hide existence
location ~ ^/(auth|users|apps|deployments|collaborators|sessions)/ {
return 404;
}
# Block web interface static files
location ~ \.(html|css|js|png|jpg|jpeg|gif|ico|svg)$ {
return 404;
}
# Allow API endpoints for mobile clients
location ~ ^/(updateCheck|reportStatus|reportDeploy|reportDownload) {
proxy_pass http://codepush_backend;
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;
# CodePush specific settings
proxy_connect_timeout 30s;
proxy_send_timeout 300s; # Large uploads
proxy_read_timeout 300s; # Large downloads
proxy_request_buffering off; # Stream large uploads
# Handle WebSocket connections for real-time updates
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Disable caching for API responses
proxy_cache off;
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
# Allow download endpoints (can be cached)
location /download {
proxy_pass http://codepush_backend;
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;
# Cache downloads for better performance
proxy_cache_valid 200 1h;
proxy_cache_valid 404 1m;
# Longer timeouts for downloads
proxy_connect_timeout 30s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
# Default deny for all other paths
location / {
return 404;
}
}
# CodePush full access proxy on port 8085 (admin access)
server {
listen 8085;
server_name localhost;
# Increase client body size for app bundles
client_max_body_size 100M;
# Allow all endpoints - full CodePush server access
location / {
proxy_pass http://codepush_backend;
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;
# CodePush specific settings
proxy_connect_timeout 30s;
proxy_send_timeout 300s; # Large uploads
proxy_read_timeout 300s; # Large downloads
proxy_request_buffering off; # Stream large uploads
# Handle WebSocket connections for real-time updates
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Disable caching for API responses
proxy_cache off;
add_header Cache-Control "no-cache, no-store, must-revalidate";
add_header Pragma "no-cache";
add_header Expires "0";
}
# Special handling for download endpoints (can be cached)
location /download {
proxy_pass http://codepush_backend;
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;
# Cache downloads for better performance
proxy_cache_valid 200 1h;
proxy_cache_valid 404 1m;
# Longer timeouts for downloads
proxy_connect_timeout 30s;
proxy_send_timeout 300s;
proxy_read_timeout 300s;
}
}
}