@@ -231,6 +231,24 @@ http {
231
231
}
232
232
{{ end }}
233
233
234
+ {{/* build the maps that will be use to validate the Whitelist */}}
235
+ {{ range $index, $server := .Servers }}
236
+ {{ range $location := $server.Locations }}
237
+ {{ $path := buildLocation $location }}
238
+
239
+ {{ if isLocationAllowed $location }}
240
+ {{ if gt (len $location.Whitelist.CIDR) 0 }}
241
+ geo $the_real_ip $deny_{{ $server.Hostname }}_{{ $path }} {
242
+ default 1;
243
+
244
+ {{ range $ip := $location.Whitelist.CIDR }}
245
+ {{ $ip }} 0;{{ end }}
246
+ }
247
+ {{ end }}
248
+ {{ end }}
249
+ {{ end }}
250
+ {{ end }}
251
+
234
252
{{/* build all the required rate limit zones. Each annotation requires a dedicated zone */}}
235
253
{{/* 1MB -> 16 thousand 64-byte states or about 8 thousand 128-byte states */}}
236
254
{{ range $zone := (buildRateLimitZones .Servers) }}
@@ -312,9 +330,9 @@ http {
312
330
313
331
{{ if isLocationAllowed $location }}
314
332
{{ if gt (len $location.Whitelist.CIDR) 0 }}
315
- {{ range $ip := $location.Whitelist.CIDR }}
316
- allow {{ $ip }};{{ end }}
317
- deny all;
333
+ if ($deny_ {{ $server.Hostname }}_{{ $path }}) {
334
+ return 403;
335
+ }
318
336
{{ end }}
319
337
320
338
port_in_redirect {{ if $location.UsePortInRedirects }}on{{ else }}off{{ end }};
@@ -362,7 +380,7 @@ http {
362
380
{{ end }}
363
381
364
382
# Pass Real IP
365
- proxy_set_header X-Real-IP $remote_addr ;
383
+ proxy_set_header X-Real-IP $the_real_ip ;
366
384
367
385
# Allow websocket connections
368
386
proxy_set_header Upgrade $http_upgrade;
0 commit comments