-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathdefault.conf.j2
598 lines (546 loc) · 34.6 KB
/
default.conf.j2
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
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
{% import 'debops__tpl_macros.j2' as debops__tpl_macros with context %}
{#
#
# ==== Default server template for debops.nginx role ====
#
# Refer to the documentation in /docs/defaults-detailed.rst
#
#}
{#
#
# ---- HTTPS, ports to listen on, default server, HTTPS redirect ----
#}
{% set nginx_version = ansible_local.nginx.version if (ansible_local|d() and ansible_local.nginx|d() and ansible_local.nginx.version|d()) else "0.0" %}
{% set nginx_tpl_robots_tag = [] if (item.robots_tag|d(nginx__http_robots_tag) is string and item.robots_tag|d(nginx__http_robots_tag) == omit)
else (
[ item.robots_tag|d(nginx__http_robots_tag) ]
if (item.robots_tag|d(nginx__http_robots_tag) is string)
else (item.robots_tag|d(nginx__http_robots_tag))) %}
{% set nginx_tpl_acme = (item.acme | default(nginx_acme)) | bool %}
{% set nginx_tpl_ssl = (item.ssl | default(nginx_pki)) | bool %}
{% set nginx_tpl_listen = item.listen | default(nginx_listen_port if nginx_listen_port else nginx_listen_socket) %}
{% if nginx_tpl_ssl | bool %}
{% set nginx_tpl_listen_ssl = item.listen_ssl | default(nginx_listen_ssl_port if nginx_listen_ssl_port else nginx_listen_ssl_socket) %}
{% endif %}
{% set nginx_tpl_default_server = [] %}
{% set nginx_tpl_ipv6only = [] %}
{% if nginx_register_default_server|d() %}
{% for name in ([ item.name ] if item.name is string else item.name) %}
{% if (name == nginx_register_default_server or
not name and nginx_register_default_server == "default") %}
{% set _ = nginx_tpl_default_server.append('default_server') %}
{% if (nginx_manage_ipv6only | bool) %}
{% set _ = nginx_tpl_ipv6only.append('ipv6only=off') %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% set nginx_tpl_default_server_ssl = [] %}
{% set nginx_tpl_ipv6only_ssl = [] %}
{% if nginx_register_default_server_ssl|d() %}
{% for name in ([ item.name ] if item.name is string else item.name) %}
{% if (name == nginx_register_default_server_ssl or
not name and nginx_register_default_server_ssl == "default") %}
{% set _ = nginx_tpl_default_server_ssl.append('default_server') %}
{% if (nginx_manage_ipv6only | bool) %}
{% set _ = nginx_tpl_ipv6only_ssl.append('ipv6only=off') %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% set nginx_tpl_default_redirect_code = '307' %}
{% set nginx_tpl_default_redirect_code_ssl = '301' %}
{% set nginx_tpl_http_redirect = item.redirect | default('https://$host$request_uri') %}
{% set nginx_tpl_pki_custom_realm = '' %}
{% set nginx_tpl_pki_custom_realm_list = [] %}
{% if (nginx_pki | bool and item.name | d() and (ansible_local|d() and ansible_local.pki|d() and ansible_local.pki.known_realms|d())) %}
{# TODO: Legacy code. Use debops__tpl_macros.j2 #}
{% for name in ([ item.name ] if item.name is string else item.name) %}
{% if name in ansible_local.pki.known_realms %}
{% set _ = nginx_tpl_pki_custom_realm_list.append(name) %}
{% elif (name.split('.')[1:] | join('.')) in ansible_local.pki.known_realms %}
{% set _ = nginx_tpl_pki_custom_realm_list.append(name.split('.')[1:] | join('.')) %}
{% endif %}
{% endfor %}
{% endif %}
{% if nginx_tpl_pki_custom_realm_list %}
{% set nginx_tpl_pki_custom_realm = nginx_tpl_pki_custom_realm_list[0] %}
{% endif %}
{#
#
# ---- SSL certificate ----
#}
{% set nginx_tpl_ssl_certificate = item.ssl_crt|d(nginx_pki_path + "/" + item.pki_realm | d(nginx_tpl_pki_custom_realm if nginx_tpl_pki_custom_realm else nginx_pki_realm) + "/" + (item.pki_crt|d(nginx_pki_crt))) %}
{#
#
# ---- SSL certificate key ----
#}
{% set nginx_tpl_ssl_certificate_key = item.ssl_key|d(nginx_pki_path + "/" + item.pki_realm | d(nginx_tpl_pki_custom_realm if nginx_tpl_pki_custom_realm else nginx_pki_realm) + "/" + (item.pki_key|d(nginx_pki_key))) %}
{#
#
# ---- SSL client CA certificate ----
#}
{% set nginx_tpl_ssl_client_certificate = item.ssl_ca|d(nginx_pki_path + "/" + item.pki_ca_realm | d(nginx_tpl_pki_custom_realm if nginx_tpl_pki_custom_realm else nginx_pki_ca_realm) + "/" + (item.pki_ca|d(nginx_pki_ca))) %}
{#
#
# ---- SSL trusted CA certificate ----
#}
{% set nginx_tpl_ssl_trusted_certificate = item.ssl_trusted
|d(nginx_pki_path + "/" + (item.pki_realm | d(nginx_tpl_pki_custom_realm if nginx_tpl_pki_custom_realm else nginx_pki_realm) + "/" + item.pki_trusted | d(nginx_pki_trusted))) %}
{#
#
# ---- Diffie-Hellman Key Exchange parameters ----
#}
{% set nginx_tpl_ssl_dhparam = item.ssl_dhparam | default(nginx_ssl_dhparam) %}
{#
#
# ---- root directory ----
#}
{% if item.owner|d() %}
{% set nginx_tpl_root = item.root | default(nginx_www + '/' + item.owner + '/sites/' + (item.name if item.name is string else item.name[0] | d('default')) + '/public') %}
{% else %}
{% set nginx_tpl_root = item.root | default(nginx_www + '/sites/' + (item.name if item.name is string else item.name[0] | d('default')) + '/public') %}
{% endif %}
{% if item.root_suffix|d() %}
{% set nginx_tpl_root = nginx_tpl_root + '/' + item.root_suffix %}
{% endif %}
{% macro print_root() %}
{% block nginx_tpl_block_root %}
{% if (not (item.root|d() | bool)) and nginx_tpl_root %}
root {{ nginx_tpl_root }};
{% endif %}
{% endblock %}
{% endmacro %}
{#
#
# ---- macro which prints location entries from 'location' hash, flat ----
#}
{% macro print_location(location,location_allow=[],location_referers=[],location_deny=[]) %}
{% if location is defined %}
{% for path in location.keys() %}
{% if location[path] %}
location {{ path }} {
{% if location_referers is defined %}
{% if location_referers[path] is defined and location_referers[path] %}
valid_referers none blocked {{ location_referers[path] | unique | join(' ') }};
if ($invalid_referer) {
return 403;
}
{% endif %}
{% endif %}
{{ item.location[path] | indent(16) | regex_replace("(?m)^\s*$", "") }}
{% if location_allow is defined %}
{% if location_allow[path] is defined and location_allow[path] %}
{% for address in location_allow[path] | unique %}
allow {{ address }};
{% endfor %}
{% if location_deny is defined %}
{% if location_deny[path] is defined %}
{% for address in location_deny[path] | unique %}
deny {{ address }};
{% endfor %}
{% endif %}
{% else %}
deny all;
{% endif %}
{% endif %}
{% endif %}
}
{% endif %}
{% endfor %}
{% endif %}
{% endmacro %}
{#
#
# ---- macro which prints location entries from 'location_list' list, recursive
#}
{% macro print_location_list(location_list) %}
{% if location_list is defined %}
{% for entry in location_list %}
{% if entry.pattern|d() and (entry.enabled|d(True) | bool) %}
location {{ entry.pattern_prefix | default('') + entry.pattern }} {
{% if entry.referers|d() %}
valid_referers none blocked {{ entry.referers | unique | join(' ') }};
if ($invalid_referer) {
return 403;
}
{% endif %}
{% if entry.options|d() %}
{{ entry.options | indent(16) | regex_replace("(?m)^\s*$", "") }}
{% endif %}
{% if entry.allow|d() %}
{% for address in entry.allow | unique %}
allow {{ address }};
{% endfor %}
{% if entry.deny|d() %}
{% for address in entry.deny | unique %}
deny {{ address }};
{% endfor %}
{% else %}
deny all;
{% endif %}
{% endif %}
{% if entry.locations|d() %}
{{ print_location_list(entry.locations) | indent(8, true) | regex_replace("(?m)^\s*$", "") }}
{% endif %}
}
{% endif %}
{% if not loop.last %}
{% endif %}
{% endfor %}
{% endif %}
{% endmacro %}
{#
#
# ---- macro which prints the nginx server block which is shared between HTTP and HTTPS
#}
{% macro print_shared_nginx_server_block() %}
{% if (not nginx_tpl_ssl and ((item.redirect|d()) or (item.redirect_to_ssl|d() | bool))) %}
return {{ item.redirect_code_ssl | default(nginx_tpl_default_redirect_code_ssl) }} {{ nginx_tpl_http_redirect }};
{% elif nginx_tpl_ssl and item.redirect_ssl|d() %}
return {{ item.redirect_code | default(nginx_tpl_default_redirect_code) }} {{ item.redirect_ssl }};
{% else %}
keepalive_timeout {{ item.keepalive | default(nginx_default_keepalive_timeout) | string }};
{% block nginx_tpl_block_log %}
{% if item.name|d() %}
{% set nginx_tpl_access_log_format = '' %}
{% if item.access_log_format is defined %}
{% set nginx_tpl_access_log_format = ' ' + item.access_log_format %}
{% elif nginx_access_log_format is defined %}
{% set nginx_tpl_access_log_format = ' ' + nginx_access_log_format %}
{% endif %}
access_log {{ (item.log_path | d(nginx_log_path)) + '/' + item.access_log | d(item.filename | d(item.name if item.name is string else item.name[0]) + '_access') }}.log{{ nginx_tpl_access_log_format }};
error_log {{ (item.log_path | d(nginx_log_path)) + '/' + item.error_log | d(item.filename | d(item.name if item.name is string else item.name[0]) + '_error') }}.log;
{% endif %}
{% endblock %}
{% block nginx_tpl_block_index %}
{% if item.index|d(True) %}
index {{ item.index | default('index.html index.htm') }};
{% endif %}
{% endblock %}
{% if nginx_real_ip_from|d() and nginx_real_ip_from %}
{% if nginx_real_ip_header|d() and nginx_real_ip_header %}
real_ip_header {{ nginx_real_ip_header }};
{% endif %}
{% if nginx_real_ip_recursive | bool %}
real_ip_recursive on;
{% elif not nginx_real_ip_recursive | bool %}
real_ip_recursive off;
{% endif %}
{% if nginx_real_ip_from is string %}
set_real_ip_from {{ nginx_real_ip_from }};
{% else %}
{% for element in nginx_real_ip_from %}
set_real_ip_from {{ element }};
{% endfor %}
{% endif %}
{% endif %}
{% if item.error_pages|d() %}
{% for code, location in item.error_pages.iteritems() %}
error_page {{ code }} {{ location }};
location {{ location }} {
internal;
}
{% endfor %}
{% endif %}
{% if item.error_pages_list|d() %}
{% for element in item.error_pages_list %}
{% if element.location|d() or element.location_options|d() %}
{% endif %}
error_page {{ element.code if (element.code is string) else (element.code | join(" ")) }} {{ element.uri }};
{% if element.location|d() or element.location_options|d() %}
location {{ element.location | d(element.uri) }} {
{{ element.location_options | indent(16, true) | regex_replace("(?m)^\s*$", "") }}
}
{% if not loop.last %}
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
{% if item.options|d() %}
{{ item.options | indent(8) | regex_replace("(?m)^\s*$", "") }}
{% endif %}
{% if item.access_policy|d() and (item.access_policy in nginx_access_policy_satisfy_map) %}
satisfy {{ nginx_access_policy_satisfy_map[item.access_policy] }};
{% elif item.allow|d() or
(item.auth_basic|d() | bool) or
(item.satisfy|d()) or
(item.access_policy|d() and
item.access_policy not in nginx_access_policy_satisfy_map) %}
satisfy {{ item.satisfy | default(nginx_default_satisfy) }};
{% endif %}
{% if item.allow|d() or item.access_policy|d() %}
{% if item.allow is defined %}
{% if item.allow is string %}
allow {{ item.allow }};
{% else %}
{% for address in item.allow | unique %}
allow {{ address }};
{% endfor %}
{% endif %}
{% endif %}
{% if item.access_policy|d() and (item.access_policy in nginx_access_policy_allow_map) %}
{% for address in nginx_access_policy_allow_map[item.access_policy] | unique %}
allow {{ address }};
{% endfor %}
{% endif %}
deny all;
{% endif %}
{% if item.access_policy|d() and (item.access_policy in nginx_access_policy_auth_basic_map) %}
auth_basic "{{ item.auth_basic_realm|d(nginx_default_auth_basic_realm) }}";
auth_basic_user_file {{ nginx_private_path + "/" + nginx_access_policy_auth_basic_map[item.access_policy] }};
{% elif item.auth_basic|d() | bool %}
auth_basic "{{ item.auth_basic_realm|d(nginx_default_auth_basic_realm) }}";
auth_basic_user_file {{ item.auth_basic_filename | default(nginx_private_path + "/" + item.auth_basic_name) }};
{% endif %}
{% if item.userdir|d()|bool %}
location ~ {{ item.userdir_regexp | d('^/~(.+?)(/.*)?$') }} {
alias {{ item.userdir_alias | d(nginx_www + '/$1/userdir/public$2') }};
index {{ item.userdir_index | d(item.index | default('index.html index.htm')) }};
{% if item.userdir_options|d() %}
{{ item.userdir_options | indent(16, true) | regex_replace("(?m)^\s*$", "") }}
{% else %}
autoindex on;
autoindex_exact_size off;
{% endif %}
}
{% endif %}
{% if item.deny_hidden|d(True) | bool %}
# Disallow access to hidden files and directories
location ~ /\. {
return 404;
}
{% endif %}
{% if item.favicon|d(True) | bool %}
location = /favicon.ico {
try_files /favicon.ico =204;
access_log off;
log_not_found off;
}
{% endif %}
{% if item.status|d(True) and (nginx_status or nginx_status_localhost) %}
location = {{ item.status_name | default(nginx_status_name) }} {
stub_status on;
access_log off;
{% if nginx_status_localhost %}
{% for address in nginx_status_localhost | unique %}
allow {{ address }};
{% endfor %}
{% endif %}
{% if nginx_status %}
{% for address in nginx_status | unique %}
allow {{ address }};
{% endfor %}
{% endif %}
{% if item.status|d() %}
{% for address in item.status | unique %}
allow {{ address }};
{% endfor %}
{% endif %}
deny all;
}
{% endif %}
{% block nginx_tpl_block_custom_status_locations %}
{% endblock %}
{% if nginx_tpl_default_server or nginx_tpl_default_server_ssl %}
include /etc/nginx/sites-default.d/*.conf;
{% endif %}
{% block nginx_tpl_block_location %}
{% if item.location|d() or item.location_list|d() %}
{% if item.location_list|d() %}
{{ print_location_list(item.location_list) }}
{% endif %}
{% if item.location|d() %}
{{ print_location(item.location, item.location_allow, item.location_referers, item.location_deny) }}
{% endif %}
{% else %}
location / {
{% block nginx_tpl_block_location_root %}
try_files {{ item.try_files|default(nginx_default_try_files) | join(' ') }} =404;
{% endblock %}
}
{% endif %}
{% endblock %}
{% block nginx_tpl_block_custom_locations %}
{% endblock %}
{% endif %}
{% endmacro %}
{#
#
# ---- nginx server template begins here ----
#}
# {{ ansible_managed }}
{% if item.name|d() %}
# nginx server configuration for:
{% for address in ([ item.name ] if item.name is string else item.name) %}
{% if nginx_tpl_ssl and not (item.redirect_to_ssl|d(True) | bool) %}
# - http://{{ address }}/
{% endif %}
# - {{ "https" if nginx_tpl_ssl else "http" }}://{{ address }}/
{% endfor %}
{% if item.by_role|d() %}
# generated by Ansible role: {{ item.by_role }}
{% endif %}
{% else %}
# nginx server default configuration
{% if item.by_role|d() %}
# generated by Ansible role: {{ item.by_role }}
{% endif %}
{% endif %}
{% if item.redirect_from|d() and item.name|d() %}
{% if item.name is string or item.name | length == 1 %}
# Cannot redirect from only one name: {{ item.name if item.name is string else item.name | join(', ') }}
{% else %}
server {
{% if item.listen|d(True) %}
{% for port in nginx_tpl_listen %}
listen {{ port|string }};
{% endfor %}
{% if nginx_tpl_ssl | bool %}
{% for port in nginx_tpl_listen_ssl %}
listen {{ port|string }} ssl;
{% endfor %}
ssl_certificate {{ nginx_tpl_ssl_certificate }};
ssl_certificate_key {{ nginx_tpl_ssl_certificate_key }};
{% endif %}
{% if item.redirect_from is iterable %}
{% for name in item.redirect_from %}
server_name {{ name }};
{% endfor %}
{% else %}{# item.redirect_from is True #}
{% for name in item.name[1:] %}
server_name {{ name }};
{% endfor %}
{% endif %}
{% endif %}
return {{ item.redirect_code | default(nginx_tpl_default_redirect_code) }} $scheme://{{ item.name if item.name is string else item.name[0] }}$request_uri;
}
{% endif %}
{% elif item.redirect_to|d() and item.name|d() %}
server {
{% if item.listen|d(True) %}
{% for port in nginx_tpl_listen %}
listen {{ port }};
{% endfor %}
{% for address in ([ item.name ] if item.name is string else item.name) %}
{% if address != item.redirect_to %}
server_name {{ address }};
{% endif %}
{% endfor %}
{% endif %}
return {{ item.redirect_code | default(nginx_tpl_default_redirect_code) }} $scheme://{{ item.redirect_to }}$request_uri;
}
{% endif %}
server {
{% if item.listen|d(True) %}
{% for port in nginx_tpl_listen %}
listen {{ port }}{% if nginx_tpl_default_server %} {{ nginx_tpl_default_server | join(" ") }}{% endif %}{% if (loop.first and nginx_tpl_ipv6only) %} {{ nginx_tpl_ipv6only | join(" ") }}{% endif %};
{% endfor %}
{% if item.name|d() %}
{% if item.redirect_from|d() %}
server_name {{ item.name if item.name is string else item.name[0] }};
{% elif item.redirect_to|d() %}
server_name {{ item.redirect_to }};
{% else %}
{% for name in ([ item.name ] if item.name is string else item.name) %}
server_name {{ name }};
{% endfor %}
{% endif %}
{% endif %}
{{ print_root() }}
{% if nginx_tpl_acme | bool %}
include snippets/acme-challenge.conf;
{% endif %}
{% endif %}
{% if nginx_tpl_ssl %}
{% if item.listen|d(True) %}
{% if not (item.redirect_to_ssl|d(True) | bool) %}
{{ print_shared_nginx_server_block() }}
{% else %}
location / {
return {{ item.redirect_code_ssl | default(nginx_tpl_default_redirect_code_ssl) }} {{ nginx_tpl_http_redirect }};
}
{% endif %}
}
server {
{% endif %}
{% for port in nginx_tpl_listen_ssl %}
listen {{ port }} ssl{% if nginx_version | version_compare('1.9.5','>=') %} http2{% elif nginx_version | version_compare('1.4','>=') %} spdy{% endif %}{% if nginx_tpl_default_server_ssl %} {{ nginx_tpl_default_server_ssl | join(" ") }}{% endif %}{% if (loop.first and nginx_tpl_ipv6only_ssl) %} {{ nginx_tpl_ipv6only_ssl | join(" ") }}{% endif %};
{% endfor %}
ssl_certificate {{ nginx_tpl_ssl_certificate }};
ssl_certificate_key {{ nginx_tpl_ssl_certificate_key }};
ssl_protocols {{ (item.tls_protocols | d(nginx_default_tls_protocols)) | join(" ") }};
ssl_prefer_server_ciphers on;
ssl_ciphers "{{ nginx_ssl_ciphers[item.ssl_ciphers | default(nginx_default_ssl_ciphers)] }}"; # TLS cipher suites set: {{ item.ssl_ciphers | default(nginx_default_ssl_ciphers) }}
{% if nginx_tpl_ssl_dhparam %}
ssl_dhparam {{ nginx_tpl_ssl_dhparam }};
{% endif %}
{% if item.ssl_curve | default(nginx_default_ssl_curve) %}
ssl_ecdh_curve {{ item.ssl_curve | default(nginx_default_ssl_curve) }};
{% endif %}
{% if nginx_version | version_compare('1.4','>=') and (item.ocsp | d(nginx_ocsp)) | bool %}
ssl_stapling on;
{% if (item.ocsp_verify | d(nginx_ocsp_verify)) | bool %}
ssl_stapling_verify on;
ssl_trusted_certificate {{ nginx_tpl_ssl_trusted_certificate }};
{% endif %}
{% if (item.ssl_verify_client | d(nginx_default_ssl_verify_client)) | bool %}
{% if item.ssl_client_certificate | d(nginx_default_ssl_client_certificate) %}
ssl_verify_client on;
ssl_client_certificate {{ item.ssl_client_certificate | d(nginx_default_ssl_client_certificate) }};
{% endif %}
{% if item.ssl_crl | d(nginx_default_ssl_crl) %}
ssl_crl {{ item.ssl_crl | d(nginx_default_ssl_crl) }};
{% endif %}
{% endif %}
resolver {{ (item.ocsp_resolvers | d(nginx_ocsp_resolvers)) | ipwrap | join(" ") }} valid=300s;
resolver_timeout 5s;
{% endif %}
{% if item.hsts_enabled|d(True) | bool %}
add_header Strict-Transport-Security "max-age={{ nginx_hsts_age }}{{ "; includeSubDomains" if nginx_hsts_subdomains|bool else "" }}{{ "; preload" if ((item.hsts_preload | d(nginx_hsts_preload)) | bool) else "" }}";
{% endif %}
{% if item.csp_enabled|d(False) | bool %}
add_header Content-Security-Policy "{{ item.csp|d("default-src https: ;") + (" " + item.csp_append|d(nginx__http_csp_append) if (item.csp_append|d(nginx__http_csp_append)) else "") }}";
{% endif %}
{% if item.csp_report_enabled|d(False) | bool %}
add_header Content-Security-Policy-Report-Only "{{ item.csp_report|d(item.csp|d("default-src https: ;")) + (" " + item.csp_append|d(nginx__http_csp_append) if (item.csp_append|d(nginx__http_csp_append)) else "") }}";
{% endif %}
{% if item.content_type_options|d(True) %}
add_header X-Content-Type-Options "{{ item.content_type_options | d('nosniff') }}"{% if nginx_version | version_compare('1.7.5','>=') %} always{% endif %};
{% endif %}
{% if item.frame_options|d(True) %}
add_header X-Frame-Options "{{ item.frame_options | d('SAMEORIGIN') }}"{% if nginx_version | version_compare('1.7.5','>=') %} always{% endif %};
{% endif %}
{% if item.xss_protection | d(nginx__http_xss_protection) != omit %}
add_header X-XSS-Protection "{{ item.xss_protection | d(nginx__http_xss_protection) }}";
{% endif %}
{% if item.http_referrer_policy | d(nginx__http_referrer_policy) != omit %}
add_header Referrer-Policy "{{ item.http_referrer_policy | d(nginx__http_referrer_policy) }}";
{% endif %}
{% for robots_tag in nginx_tpl_robots_tag %}
add_header X-Robots-Tag "{{ robots_tag }}";
{% endfor %}
{% if item.permitted_cross_domain_policies | d(nginx__http_permitted_cross_domain_policies) != omit %}
add_header X-Permitted-Cross-Domain-Policies "{{ item.permitted_cross_domain_policies | d(nginx__http_permitted_cross_domain_policies) }}";
{% endif %}
{% if item.name|d() %}
{% if item.redirect_from|d() %}
server_name {{ item.name if item.name is string else item.name[0] }};
{% elif item.redirect_to|d() %}
server_name {{ item.redirect_to }};
{% else %}
{% for name in ([ item.name ] if item.name is string else item.name) %}
server_name {{ name }};
{% endfor %}
{% endif %}
{% endif %}
{% endif %}
{% if nginx_tpl_ssl | bool %}
{{ print_root() }}
{% if nginx_tpl_acme | bool %}
include snippets/acme-challenge.conf;
{% endif %}
{% endif %}
{# ---- end of nginx_tpl_ssl ---- #}
{{ print_shared_nginx_server_block() }}
}