forked from jcmoraisjr/haproxy-ingress
-
Notifications
You must be signed in to change notification settings - Fork 0
/
haproxy.tmpl
1033 lines (943 loc) · 38 KB
/
haproxy.tmpl
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
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# # HAProxy Ingress Controller
# # --------------------------
# # This file is automatically updated, do not edit
# #
#
{{- $cfg := . }}
{{- $global := $cfg.Global }}
global
daemon
{{- if gt $global.Procs.Nbproc 1 }}
nbproc {{ $global.Procs.Nbproc }}
{{- end }}
{{- if gt $global.Procs.Nbthread 1 }}
nbthread {{ $global.Procs.Nbthread }}
{{- end }}
{{- if $global.Procs.CPUMap }}
cpu-map {{ $global.Procs.CPUMap }}
{{- end }}
stats socket {{ default "--" $global.AdminSocket }} level admin expose-fd listeners
{{- if gt $global.Procs.Nbproc 1 }} process 1{{ end }}
{{- if $global.LoadServerState }}
server-state-file state-global
server-state-base /var/lib/haproxy/
{{- end }}
maxconn {{ $global.MaxConn }}
{{- if $global.Timeout.Stop }}
hard-stop-after {{ $global.Timeout.Stop }}
{{- end }}
{{- if $global.Syslog.Endpoint }}
log {{ $global.Syslog.Endpoint }} len {{ $global.Syslog.Length }} format {{ $global.Syslog.Format }} local0
log-tag {{ $global.Syslog.Tag }}
{{- end }}
lua-load /usr/local/etc/haproxy/lua/send-response.lua
lua-load /usr/local/etc/haproxy/lua/auth-request.lua
{{- if $global.SSL.DHParam.Filename }}
ssl-dh-param-file {{ $global.SSL.DHParam.Filename }}
{{- else }}
tune.ssl.default-dh-param {{ $global.SSL.DHParam.DefaultMaxSize }}
{{- end }}
{{- if $global.SSL.Engine }}
ssl-engine {{ $global.SSL.Engine }}
{{- if $global.SSL.ModeAsync }}
ssl-mode-async
{{- end }}
{{- end }}
{{- if $global.SSL.Ciphers }}
ssl-default-bind-ciphers {{ $global.SSL.Ciphers }}
{{- end }}
{{- if $global.SSL.CipherSuites }}
ssl-default-bind-ciphersuites {{ $global.SSL.CipherSuites }}
{{- end }}
{{- if $global.SSL.Options }}
ssl-default-bind-options {{ $global.SSL.Options }}
{{- end }}
{{- if $global.SSL.BackendCiphers }}
ssl-default-server-ciphers {{ $global.SSL.BackendCiphers }}
{{- end }}
{{- if $global.SSL.BackendCipherSuites }}
ssl-default-server-ciphersuites {{ $global.SSL.BackendCipherSuites }}
{{- end }}
{{- if $global.SSL.BackendOptions }}
ssl-default-server-options {{ $global.SSL.BackendOptions }}
{{- end }}
{{- range $snippet := $global.CustomConfig }}
{{ $snippet }}
{{- end }}
defaults
log global
{{- if $global.LoadServerState }}
load-server-state-from-file global
{{- end }}
maxconn {{ $global.MaxConn }}
{{- if $global.DrainSupport.Drain }}
option persist
{{- if $global.DrainSupport.Redispatch }}
option redispatch
{{- end }}
{{- else }}
option redispatch
{{- end }}
option dontlognull
option http-server-close
option http-keep-alive
{{- if $global.UseHTX }}
option http-use-htx
{{- end }}
timeout client {{ default "--" $global.Timeout.Client }}
{{- if $global.Timeout.ClientFin }}
timeout client-fin {{ $global.Timeout.ClientFin }}
{{- end }}
timeout connect {{ default "--" $global.Timeout.Connect }}
{{- if $global.Timeout.KeepAlive }}
timeout http-keep-alive {{ $global.Timeout.KeepAlive }}
{{- end }}
{{- if $global.Timeout.HTTPRequest }}
timeout http-request {{ $global.Timeout.HTTPRequest }}
{{- end }}
{{- if $global.Timeout.Queue }}
timeout queue {{ $global.Timeout.Queue }}
{{- end }}
timeout server {{ default "--" $global.Timeout.Server }}
{{- if $global.Timeout.ServerFin }}
timeout server-fin {{ $global.Timeout.ServerFin }}
{{- end }}
{{- if $global.Timeout.Tunnel }}
timeout tunnel {{ $global.Timeout.Tunnel }}
{{- end }}
{{- range $snippet := $global.CustomDefaults }}
{{ $snippet }}
{{- end }}
{{- if $global.DNS.Resolvers }}
# # # # # # # # # # # # # # # # # # #
# #
# DNS RESOLVERS
#
{{- range $resolver := $global.DNS.Resolvers }}
resolvers {{ $resolver.Name }}
{{- range $ns := $resolver.Nameservers }}
nameserver {{ $ns.Name }} {{ $ns.Endpoint }}
{{- end }}
accepted_payload_size {{ $resolver.AcceptedPayloadSize }}
hold obsolete {{ $resolver.HoldObsolete }}
hold valid {{ $resolver.HoldValid }}
timeout retry {{ $resolver.TimeoutRetry }}
{{- end }}
{{- end }}
{{- $userlists := $cfg.Userlists }}
{{- if $userlists }}
# # # # # # # # # # # # # # # # # # #
# #
# USER LISTS
#
{{- range $userlist := $userlists }}
userlist {{ $userlist.Name }}
{{- range $user := $userlist.Users }}
user {{ $user.Name }} {{ if not $user.Encrypted }}insecure-{{ end }}password {{ $user.Passwd }}
{{- end }}
{{- end }}
{{- end }}
{{- if $cfg.TCPBackends }}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# # TCP SERVICES
# #
#
{{- range $backend := $cfg.TCPBackends }}
listen _tcp_{{ $backend.Name }}_{{ $backend.Port }}
{{- $ssl := $backend.SSL }}
bind {{ $global.Bind.TCPBindIP }}:{{ $backend.Port }}
{{- if $ssl.Filename }} ssl crt {{ $ssl.Filename }}{{ end }}
{{- if $backend.ProxyProt.Decode }} accept-proxy{{ end }}
mode tcp
{{- /*------------------------------------*/}}
{{- if $global.UseHTX }}
no option http-use-htx
{{- end }}
{{- /*------------------------------------*/}}
{{- if $global.Syslog.Endpoint }}
{{- if eq $global.Syslog.TCPLogFormat "default" }}
option tcplog
{{- else if $global.Syslog.TCPLogFormat }}
log-format {{ $global.Syslog.TCPLogFormat }}
{{- else }}
no log
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- $outProxyProtVersion := $backend.ProxyProt.EncodeVersion }}
{{- range $ep := $backend.Endpoints }}
server {{ $ep.Name }} {{ $ep.Target }}
{{- if $backend.CheckInterval }} check port {{ $ep.Port }} inter {{ $backend.CheckInterval }}{{ end }}
{{- if eq $outProxyProtVersion "v1" }} send-proxy
{{- else if eq $outProxyProtVersion "v2" }} send-proxy-v2
{{- end }}
{{- end }}
{{- end }}{{/* range TCPBackends */}}
{{- end }}{{/* if has TCPBackend */}}
{{- if $cfg.Backends }}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# # BACKENDS
# #
#
{{- range $backend := $cfg.Backends }}
backend {{ $backend.ID }}
mode {{ if $backend.ModeTCP }}tcp{{ else }}http{{ end }}
{{- if $backend.BalanceAlgorithm }}
balance {{ $backend.BalanceAlgorithm }}
{{- end }}
{{- $timeout := $backend.Timeout }}
{{- if $timeout.Connect }}
timeout connect {{ $timeout.Connect }}
{{- end }}
{{- if $timeout.KeepAlive }}
timeout http-keep-alive {{ $timeout.KeepAlive }}
{{- end }}
{{- if $timeout.HTTPRequest }}
timeout http-request {{ $timeout.HTTPRequest }}
{{- end }}
{{- if $timeout.Queue }}
timeout queue {{ $timeout.Queue }}
{{- end }}
{{- if $timeout.Server }}
timeout server {{ $timeout.Server }}
{{- end }}
{{- if $timeout.ServerFin }}
timeout server-fin {{ $timeout.ServerFin }}
{{- end }}
{{- if $timeout.Tunnel }}
timeout tunnel {{ $timeout.Tunnel }}
{{- end }}
{{- /*------------------------------------*/}}
{{- if or $backend.Limit.Connections $backend.Limit.RPS }}
stick-table type ip size 200k expire 5m store conn_cur,conn_rate(1s)
{{- end }}
{{- /*------------------------------------*/}}
{{- if $backend.HealthCheck.URI }}
option httpchk {{ $backend.HealthCheck.URI }}
{{- end }}
{{- /*------------------------------------*/}}
{{- /* MODE TCP */}}
{{- /*------------------------------------*/}}
{{- if $backend.ModeTCP }}
{{- /*------------------------------------*/}}
{{- if $global.UseHTX }}
no option http-use-htx
{{- end }}
{{- /*------------------------------------*/}}
{{- if $backend.WhitelistTCP }}
{{- range $w1 := short 10 $backend.WhitelistTCP }}
acl wlist_src src{{ range $w := $w1 }} {{ $w }}{{ end }}
{{- end }}
tcp-request content reject if !wlist_src
{{- end }}
{{- /*------------------------------------*/}}
{{- if or $backend.Limit.RPS $backend.Limit.Connections }}
tcp-request content track-sc1 src
{{- if $backend.Limit.Whitelist }}
{{- range $w1 := short 10 $backend.Limit.Whitelist }}
acl wlist_conn src{{ range $w := $w1 }} {{ $w }}{{ end }}
{{- end }}
{{- end }}
{{- if $backend.Limit.Connections }}
tcp-request content reject if
{{- if $backend.Limit.Whitelist }} !wlist_conn{{ end }}
{{- "" }} { sc1_conn_cur gt {{ $backend.Limit.Connections }} }
{{- end }}
{{- if $backend.Limit.RPS }}
tcp-request content reject if
{{- if $backend.Limit.Whitelist }} !wlist_conn{{ end }}
{{- "" }} { sc1_conn_rate gt {{ $backend.Limit.RPS }} }
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- /* MODE HTTP */}}
{{- /*------------------------------------*/}}
{{- else }}{{/*** if $backend.ModeTCP ***/}}
{{- /*------------------------------------*/}}
{{- if $backend.HSTS }}
acl https-request ssl_fc
{{- $hasHTTPSocket := $global.Bind.ToHTTPSocketID }}
{{- if $hasHTTPSocket }}
acl https-request so_id {{ $global.Bind.ToHTTPSocketID }}
{{- end }}
{{- end }}
{{- if or $backend.TLS.HasTLSAuth }}
acl local-offload ssl_fc
{{- end }}
{{- /*------------------------------------*/}}
{{- if or $backend.Limit.RPS $backend.Limit.Connections }}
http-request track-sc1 src
{{- if $backend.Limit.Whitelist }}
{{- range $w1 := short 10 $backend.Limit.Whitelist }}
acl wlist_conn src{{ range $w := $w1 }} {{ $w }}{{ end }}
{{- end }}
{{- end }}
{{- if $backend.Limit.Connections }}
http-request deny deny_status 429 if
{{- if $backend.Limit.Whitelist }} !wlist_conn{{ end }}
{{- "" }} { sc1_conn_cur gt {{ $backend.Limit.Connections }} }
{{- end }}
{{- if $backend.Limit.RPS }}
http-request deny deny_status 429 if
{{- if $backend.Limit.Whitelist }} !wlist_conn{{ end }}
{{- "" }} { sc1_conn_rate gt {{ $backend.Limit.RPS }} }
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- if $backend.NeedACL }}
{{- range $path := reverse $backend.Paths }}
# {{ $path.ID }} = {{ $path.Hostpath }}
{{- end }}
http-request set-var(txn.pathID) base,map_beg({{ $backend.PathsMap.MatchFile }},_nomatch)
{{- end }}
{{- /*------------------------------------*/}}
{{- range $i, $wlistCfg := $backend.WhitelistHTTP }}
{{- $wlist := $wlistCfg.Config }}
{{- if $wlist }}
{{- range $w1 := short 10 $wlist }}
acl wlist_src{{ $i }} src{{ range $w := $w1 }} {{ $w }}{{ end }}
{{- end }}
http-request deny if
{{- if gt (len $backend.WhitelistHTTP) 1 }} { var(txn.pathID) {{ $wlistCfg.Paths.IDList }} }{{ end }}
{{- "" }} !wlist_src{{ $i }}
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- $needACL := gt (len $backend.AuthHTTP) 1 }}
{{- range $authCfg := $backend.AuthHTTP }}
{{- if $authCfg.UserlistName }}
http-request auth
{{- if $authCfg.Realm }} realm "{{ $authCfg.Realm }}"{{ end }}
{{- "" }} if{{ if and $backend.HasCorsEnabled }} !METH_OPTIONS{{ end }}
{{- if $needACL }} { var(txn.pathID) {{ $authCfg.Paths.IDList }} }{{ end }}
{{- "" }} !{ http_auth({{ $authCfg.UserlistName }}) }
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- if and $global.ModSecurity.Endpoints $backend.HasModsec }}
filter spoe engine modsecurity config /etc/haproxy/spoe-modsecurity.conf
{{- $needACL := gt (len $backend.WAF) 1 }}
{{- range $waf := $backend.WAF }}
{{- if eq $waf.Config "modsecurity" }}
http-request deny if { var(txn.modsec.code) -m int gt 0 }
{{- if $needACL }} { var(txn.pathID) {{ $waf.Paths.IDList }} }{{ end }}
{{- end }}
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- if $backend.TLS.HasTLSAuth }}
{{- $needSSLACL := not $backend.HasSSLRedirect }}
http-request set-header {{ $global.SSL.HeadersPrefix }}-Client-CN %{+Q}[ssl_c_s_dn(cn)]{{ if $needSSLACL }} if local-offload{{ end }}
http-request set-header {{ $global.SSL.HeadersPrefix }}-Client-DN %{+Q}[ssl_c_s_dn]{{ if $needSSLACL }} if local-offload{{ end }}
http-request set-header {{ $global.SSL.HeadersPrefix }}-Client-SHA1 %{+Q}[ssl_c_sha1,hex]{{ if $needSSLACL }} if local-offload{{ end }}
{{- if $backend.TLS.AddCertHeader }}
http-request set-header {{ $global.SSL.HeadersPrefix }}-Client-Cert %{+Q}[ssl_c_der,base64]{{ if $needSSLACL }} if local-offload{{ end }}
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- if $backend.HasCorsEnabled }}
http-request use-service lua.send-response if METH_OPTIONS
{{- end }}
{{- /*------------------------------------*/}}
{{- if eq $global.ForwardFor "add" }}
http-request set-header X-Original-Forwarded-For %[hdr(x-forwarded-for)] if { hdr(x-forwarded-for) -m found }
http-request del-header x-forwarded-for
option forwardfor
{{- else if eq $global.ForwardFor "ifmissing" }}
option forwardfor if-none
{{- end }}
{{- /*------------------------------------*/}}
{{- if $backend.OAuth.Impl }}
{{- $oauth := $backend.OAuth }}
{{- if eq $oauth.Impl "oauth2_proxy" }}
http-request set-header X-Real-IP %[src]
http-request lua.auth-request {{ $oauth.BackendName }} {{ $oauth.URIPrefix }}/auth
http-request redirect location {{ $oauth.URIPrefix }}/start?rd=%[path] if !{ path_beg {{ $oauth.URIPrefix }}/ } !{ var(txn.auth_response_successful) -m bool }
{{- range $header, $attr := $oauth.Headers }}
http-request set-header {{ $header }} %[var(txn.{{ $attr }})] if { var(txn.{{ $attr }}) -m found }
{{- end }}
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- if $backend.Cookie.Name }}
{{- $cookie := $backend.Cookie }}
cookie {{ $cookie.Name }} {{ $cookie.Strategy }}
{{- if eq $cookie.Strategy "insert" }} indirect nocache httponly{{ end }}
{{- if $cookie.Dynamic }} dynamic{{ end }}
{{- if $cookie.Dynamic }}
dynamic-cookie-key "{{ $global.Cookie.Key }}"
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- range $snippet := $backend.CustomConfig }}
{{ $snippet }}
{{- end }}
{{- /*------------------------------------*/}}
{{- $needACL := gt (len $backend.RewriteURL) 1 }}
{{- range $rewriteCfg := $backend.RewriteURL }}
{{- $rewrite := $rewriteCfg.Config }}
{{- if $rewrite }}
{{- range $path := $rewriteCfg.Paths.Items }}
{{- if eq $rewrite "/" }}
reqrep ^([^:\ ]*)\ {{ $path.Path }}/?(.*)$ \1\ {{ $rewrite }}\2
{{- if $needACL }} if { var(txn.pathID) {{ $path.ID }} }{{ end }}
{{- else }}
reqrep ^([^:\ ]*)\ {{ $path.Path }}(.*)$ \1\ {{ $rewrite }}{{ if hasSuffix $path.Path "/" }}/{{ end }}\2
{{- if $needACL }} if { var(txn.pathID) {{ $path.ID }} }{{ end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- $needACL := gt (len $backend.HSTS) 1 }}
{{- range $hstsCfg := $backend.HSTS }}
{{- $hsts := $hstsCfg.Config }}
{{- if $hsts.Enabled }}
{{- $paths := $hstsCfg.Paths }}
{{- $needSSLACL := not ($backend.HasSSLRedirectPaths $paths) }}
http-response set-header Strict-Transport-Security "max-age={{ $hsts.MaxAge }}
{{- if $hsts.Subdomains }}; includeSubDomains{{ end }}
{{- if $hsts.Preload }}; preload{{ end }}"
{{- if or $needSSLACL $needACL }} if
{{- if $needSSLACL }} https-request{{ end }}
{{- if $needACL }} { var(txn.pathID) {{ $paths.IDList }} }{{ end }}
{{- end }}
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- $needACL := gt (len $backend.Cors) 1 }}
{{- range $corsCfg := $backend.Cors }}
{{- $cors := $corsCfg.Config }}
{{- if $cors.Enabled }}
{{- $paths := $corsCfg.Paths }}
http-response set-status 204 reason "No Content" if METH_OPTIONS
{{- if $needACL }} { var(txn.pathID) {{ $paths.IDList }} }{{ end }}
http-response set-header Content-Type "text/plain" if METH_OPTIONS
{{- if $needACL }} { var(txn.pathID) {{ $paths.IDList }} }{{ end }}
http-response set-header Content-Length "0" if METH_OPTIONS
{{- if $needACL }} { var(txn.pathID) {{ $paths.IDList }} }{{ end }}
http-response set-header Access-Control-Max-Age "{{ $cors.MaxAge }}" if METH_OPTIONS
{{- if $needACL }} { var(txn.pathID) {{ $paths.IDList }} }{{ end }}
http-response set-header Access-Control-Allow-Origin "{{ $cors.AllowOrigin }}"
{{- if $needACL }} if { var(txn.pathID) {{ $paths.IDList }} }{{ end }}
http-response set-header Access-Control-Allow-Methods "{{ $cors.AllowMethods }}"
{{- if $needACL }} if { var(txn.pathID) {{ $paths.IDList }} }{{ end }}
http-response set-header Access-Control-Allow-Headers "{{ $cors.AllowHeaders }}"
{{- if $needACL }} if { var(txn.pathID) {{ $paths.IDList }} }{{ end }}
{{- if $cors.AllowCredentials }}
http-response set-header Access-Control-Allow-Credentials "{{ $cors.AllowCredentials }}"
{{- if $needACL }} if { var(txn.pathID) {{ $paths.IDList }} }{{ end }}
{{- end }}
{{- if $cors.ExposeHeaders }}
http-response set-header Access-Control-Expose-Headers "{{ $cors.ExposeHeaders }}"
{{- if $needACL }} if { var(txn.pathID) {{ $paths.IDList }} }{{ end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}{{/*** if $backend.ModeTCP ***/}}
{{- /*------------------------------------*/}}
{{- if $backend.Resolver }}
{{- $portIsNumber := ne (int64 $backend.Port) 0 }}
server-template srv {{ len $backend.Endpoints }}
{{- " " }}{{ if not $portIsNumber }}_{{ $backend.Port }}._tcp.{{ end }}
{{- $backend.Name }}.{{ $backend.Namespace }}.svc.{{ $global.DNS.ClusterDomain }}
{{- if $portIsNumber }}:{{ $backend.Port }}{{ end }}
{{- "" }} resolvers {{ $backend.Resolver }} resolve-prefer ipv4 init-addr none
{{- template "backend" map $backend }}
{{- else }}
{{- /* Iterate twice because header takes precedence */}}
{{- if $backend.BlueGreen.HeaderName }}
{{- range $ep := $backend.Endpoints }}
{{- if $ep.Label }}
use-server {{ $ep.Name }} if { req.hdr({{ $backend.BlueGreen.HeaderName }}) {{ $ep.Label }} }
{{- end }}
{{- end }}
{{- end }}
{{- if $backend.BlueGreen.CookieName }}
{{- range $ep := $backend.Endpoints }}
{{- if $ep.Label }}
use-server {{ $ep.Name }} if { req.cook({{ $backend.BlueGreen.CookieName }}) {{ $ep.Label }} }
{{- end }}
{{- end }}
{{- end }}
{{- range $ep := $backend.Endpoints }}
server {{ $ep.Name }} {{ $ep.IP }}:{{ $ep.Port }}
{{- if not $ep.Enabled }} disabled{{ end }}
{{- "" }} weight {{ $ep.Weight }}
{{- if and (not $backend.ModeTCP) ($backend.Cookie.Name) (not $backend.Cookie.Dynamic) }} cookie {{ $ep.Name }}{{ end }}
{{- template "backend" map $backend }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}{{/* if has Backends */}}
{{- define "backend" }}
{{- $backend := .p1 }}
{{- $server := $backend.Server }}
{{- if eq $server.Protocol "h2" }} proto h2{{ end }}
{{- if $server.MaxConn }} maxconn {{ $server.MaxConn }}{{ end }}
{{- if $server.MaxQueue }} maxqueue {{ $server.MaxQueue }}{{ end }}
{{- if $server.Secure }} ssl
{{- if $server.Ciphers }} ciphers {{ $server.Ciphers }}{{ end }}
{{- if $server.CipherSuites }} ciphersuites {{ $server.CipherSuites }}{{ end }}
{{- if $server.Options }} {{ $server.Options }}{{ end }}
{{- if $server.CrtFilename }} crt {{ $server.CrtFilename }}{{ end }}
{{- if $server.CAFilename }} verify required ca-file {{ $server.CAFilename }}
{{- if $server.CRLFilename }} crl-file {{ $server.CRLFilename }}{{ end }}
{{- else }} verify none
{{- end }}
{{- end }}
{{- if $server.SendProxy }} {{ $server.SendProxy }}{{ end }}
{{- $agent := $backend.AgentCheck }}
{{- $hc := $backend.HealthCheck }}
{{- if or $hc.Port $hc.Addr $hc.Interval $hc.RiseCount $hc.FallCount }} check
{{- if $hc.Port }} port {{ $hc.Port }}{{ end }}
{{- if $hc.Addr }} addr {{ $hc.Addr }}{{ end }}
{{- if $hc.Interval }} inter {{ $hc.Interval }}{{ end }}
{{- if $hc.RiseCount }} rise {{ $hc.RiseCount }}{{ end }}
{{- if $hc.FallCount }} fall {{ $hc.FallCount }}{{ end }}
{{- end }}
{{- if $agent.Port }} agent-check agent-port {{ $agent.Port }}
{{- if $agent.Addr }} agent-addr {{ $agent.Addr }}{{ end }}
{{- if $agent.Interval }} agent-inter {{ $agent.Interval }}{{ end }}
{{- if $agent.Send }} agent-send {{ $agent.Send }}{{ end }}
{{- end }}
{{- end }}
{{- if $cfg.Backends }}
# # # # # # # # # # # # # # # # # # #
# #
# Error pages
#
{{- if not $cfg.DefaultBackend }}
backend _error404
mode http
errorfile 400 /usr/local/etc/haproxy/errors/404.http
http-request deny deny_status 400
{{- end }}
backend _error413
mode http
errorfile 400 /usr/local/etc/haproxy/errors/413.http
http-request deny deny_status 400
backend _error421
mode http
errorfile 400 /usr/local/etc/haproxy/errors/421.http
http-request deny deny_status 400
backend _error495
mode http
errorfile 400 /usr/local/etc/haproxy/errors/495.http
http-request deny deny_status 400
backend _error496
mode http
errorfile 400 /usr/local/etc/haproxy/errors/496.http
http-request deny deny_status 400
{{- end }}{{/* if has Backends */}}
{{- $fgroup := $cfg.FrontendGroup }}
{{- if $fgroup }}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# # FRONTENDS
# #
#
{{- $frontends := $fgroup.Frontends }}
{{- if $fgroup.HasTCPProxy }}
# # # # # # # # # # # # # # # # # # #
# #
# TCP/TLS frontend
#
listen _front__tls
mode tcp
bind {{ $global.Bind.HTTPSBindIP }}:{{ $global.Bind.HTTPSPort }}{{ if $global.Bind.AcceptProxy }} accept-proxy{{ end }}
{{- /*------------------------------------*/}}
{{- if $global.UseHTX }}
no option http-use-htx
{{- end }}
{{- /*------------------------------------*/}}
{{- if $global.Syslog.Endpoint }}
{{- if eq $global.Syslog.HTTPSLogFormat "default" }}
option tcplog
{{- else if $global.Syslog.HTTPSLogFormat }}
log-format {{ $global.Syslog.HTTPSLogFormat }}
{{- else }}
no log
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
tcp-request inspect-delay 5s
{{- /*------------------------------------*/}}
{{- if $fgroup.HasSSLPassthrough }}
tcp-request content set-var(req.sslpassback)
{{- "" }} req.ssl_sni,lower,map({{ $fgroup.SSLPassthroughMap.MatchFile }},_nomatch)
{{- end }}
{{- if $fgroup.SSLPassthroughMap.HasRegex }}
{{- /*** TODO map_reg() running on every request ***/}}
tcp-request content set-var(req.sslpassregback)
{{- "" }} req.ssl_sni,lower,map_reg({{ $fgroup.SSLPassthroughMap.RegexFile }},_nomatch)
{{- "" }} if { var(req.sslpassback) _nomatch }
{{- end }}
{{- /*------------------------------------*/}}
tcp-request content accept if { req.ssl_hello_type 1 }
{{- /*------------------------------------*/}}
{{- if $fgroup.HasSSLPassthrough }}
use_backend %[var(req.sslpassback)] unless { var(req.sslpassback) _nomatch }
{{- end }}
{{- range $frontend := $frontends }}
{{- if $frontend.Hosts }}
{{- $bind := $frontend.Bind }}
## {{ $bind.Name }}
use-server _server{{ $bind.Name }} if { req.ssl_sni -i -f {{ $bind.UseServerList.MatchFile }} }
server _server{{ $bind.Name }} {{ $bind.Socket }} send-proxy-v2 weight 0
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- if $fgroup.SSLPassthroughMap.HasRegex }}
use_backend %[var(req.sslpassback)] unless { var(req.sslpassback) _nomatch }
{{- end }}
{{- range $frontend := $frontends }}
{{- $bind := $frontend.Bind }}
{{- if $bind.UseServerList.HasRegex }}
## {{ $bind.Name }} wildcard
use-server _server{{ $bind.Name }}_wildcard if { req.ssl_sni -i -m reg -f {{ $bind.UseServerList.RegexFile }} }
server _server{{ $bind.Name }}_wildcard {{ $bind.Socket }} send-proxy-v2 weight 0
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
# default backend
server _default_server{{ $fgroup.DefaultBind.Name }} {{ $fgroup.DefaultBind.Socket }} send-proxy-v2
{{- end }}
# # # # # # # # # # # # # # # # # # #
# #
# HTTP frontend
#
frontend _front_http
mode http
bind {{ $global.Bind.HTTPBindIP }}:{{ $global.Bind.HTTPPort }}{{ if $global.Bind.AcceptProxy }} accept-proxy{{ end }}
{{- /*------------------------------------*/}}
{{- if $global.Syslog.Endpoint }}
{{- if $global.Syslog.HTTPLogFormat }}
log-format {{ $global.Syslog.HTTPLogFormat }}
{{- else }}
option httplog
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
http-request set-var(req.base) base,regsub(:[0-9]+/,/)
{{- /*------------------------------------*/}}
{{- if $fgroup.HTTPSRedirMap.HasRegex }}
http-request set-var(req.redir)
{{- "" }} var(req.base),map_beg({{ $fgroup.HTTPSRedirMap.MatchFile }},_nomatch)
http-request redirect scheme https if { var(req.redir) yes }
http-request redirect scheme https if { var(req.redir) _nomatch }
{{- "" }} { var(req.base),map_reg({{ $fgroup.HTTPSRedirMap.RegexFile }},_nomatch) yes }
{{- else }}
http-request redirect scheme https if { var(req.base),map_beg({{ $fgroup.HTTPSRedirMap.MatchFile }},_nomatch) yes }
{{- end }}
{{- /*------------------------------------*/}}
{{- if $fgroup.HTTPRootRedirMap.HasHost }}
http-request set-var(req.host) hdr(host),lower,regsub(:[0-9]+/,/)
http-request set-var(req.rootredir)
{{- "" }} var(req.host),map({{ $fgroup.HTTPRootRedirMap.MatchFile }},_nomatch)
{{- if $fgroup.HTTPRootRedirMap.HasRegex }}
http-request set-var(req.rootredir)
{{- "" }} var(req.host),map_reg({{ $fgroup.HTTPRootRedirMap.RegexFile }},_nomatch) if { var(req.rootredir) _nomatch }
{{- end }}
http-request redirect location %[var(req.rootredir)] if { path / } !{ var(req.rootredir) _nomatch }
{{- end }}
{{- /*------------------------------------*/}}
http-request set-header X-Forwarded-Proto http
http-request del-header {{ $global.SSL.HeadersPrefix }}-Client-CN
http-request del-header {{ $global.SSL.HeadersPrefix }}-Client-DN
http-request del-header {{ $global.SSL.HeadersPrefix }}-Client-SHA1
http-request del-header {{ $global.SSL.HeadersPrefix }}-Client-Cert
{{- /*------------------------------------*/}}
http-request set-var(req.backend) var(req.base),map_beg({{ $fgroup.HTTPFrontsMap.MatchFile }},_nomatch)
{{- if $fgroup.HTTPFrontsMap.HasRegex }}
http-request set-var(req.backend)
{{- "" }} var(req.base),map_reg({{ $fgroup.HTTPFrontsMap.RegexFile }},_nomatch)
{{- "" }} if { var(req.backend) _nomatch }
{{- end }}
{{- /*------------------------------------*/}}
{{- range $snippet := $global.CustomFrontend }}
{{ $snippet }}
{{- end }}
{{- /*------------------------------------*/}}
use_backend %[var(req.backend)] unless { var(req.backend) _nomatch }
{{- template "defaultbackend" map $cfg }}
# # # # # # # # # # # # # # # # # # #
# #
# HTTPS frontends
#
{{- range $frontend := $frontends }}
frontend {{ $frontend.Name }}
mode http
{{- /*------------------------------------*/}}
{{- $bind := $frontend.Bind }}
{{- if $bind.Socket }}
bind {{ $bind.Socket }}
{{- if $bind.ID }} id {{ $bind.ID }}{{ end }}
{{- if $bind.AcceptProxy }} accept-proxy{{ end }}
{{- "" }} ssl alpn {{ $bind.ALPN }}
{{- "" }} crt-list {{ $bind.CrtList.MatchFile }}
{{- "" }} ca-ignore-err all crt-ignore-err all
{{- end }}
{{- $bind := $fgroup.ToHTTPBind }}
{{- if $bind.Socket }}
bind {{ $bind.Socket }}
{{- if $bind.ID }} id {{ $bind.ID }}{{ end }}
{{- if $bind.AcceptProxy }} accept-proxy{{ end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- $hasHTTPSocket := $global.Bind.ToHTTPSocketID }}
{{- if $hasHTTPSocket }}
acl local-offload ssl_fc
{{- end }}
{{- /*------------------------------------*/}}
{{- if $frontend.Timeout.Client }}
timeout client {{ $frontend.Timeout.Client }}
{{- end }}
{{- if $frontend.Timeout.ClientFin }}
timeout client-fin {{ $frontend.Timeout.ClientFin }}
{{- end }}
{{- /*------------------------------------*/}}
{{- if $global.Syslog.Endpoint }}
{{- if $global.Syslog.HTTPLogFormat }}
log-format {{ $global.Syslog.HTTPLogFormat }}
{{- else }}
option httplog
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- if or $frontend.HasTLSAuth $frontend.HostBackendsMap.HasRegex $frontend.HasVarNamespace $frontend.HasMaxBody }}
http-request set-var(req.base) base,lower,regsub(:[0-9]+/,/)
http-request set-var(req.hostbackend)
{{- "" }} var(req.base),map_beg({{ $frontend.HostBackendsMap.MatchFile }},_nomatch)
{{- else }}
http-request set-var(req.hostbackend) base,lower,regsub(:[0-9]+/,/)
{{- "" }},map_beg({{ $frontend.HostBackendsMap.MatchFile }},_nomatch)
{{- end }}
{{- if $frontend.HostBackendsMap.HasRegex }}
http-request set-var(req.hostbackend)
{{- "" }} var(req.base),map_reg({{ $frontend.HostBackendsMap.RegexFile }},_nomatch)
{{- "" }} if { var(req.hostbackend) _nomatch }
{{- end }}
{{- /*------------------------------------*/}}
{{- if or $frontend.HasTLSAuth $frontend.RootRedirMap.HasHost }}
http-request set-var(req.host) hdr(host),lower,regsub(:[0-9]+/,/)
{{- end }}
{{- if $frontend.RootRedirMap.HasHost }}
http-request set-var(req.rootredir)
{{- "" }} var(req.host),map({{ $frontend.RootRedirMap.MatchFile }},_nomatch)
{{- if $frontend.RootRedirMap.HasRegex }}
http-request set-var(req.rootredir)
{{- "" }} var(req.host),map_reg({{ $frontend.RootRedirMap.RegexFile }},_nomatch) if { var(req.rootredir) _nomatch }
{{- end }}
http-request redirect location %[var(req.rootredir)] if { path / } !{ var(req.rootredir) _nomatch }
{{- end }}
{{- /*------------------------------------*/}}
{{- if $frontend.HasVarNamespace }}
http-request set-var(txn.namespace)
{{- "" }} var(req.base),map_beg({{ $frontend.VarNamespaceMap.MatchFile }},-)
{{- if $frontend.VarNamespaceMap.HasRegex }}
http-request set-var(txn.namespace)
{{- "" }} var(req.base),map_reg({{ $frontend.VarNamespaceMap.RegexFile }},-)
{{- "" }} if { var(txn.namespace) - }
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
http-request set-header X-Forwarded-Proto https
http-request del-header {{ $global.SSL.HeadersPrefix }}-Client-CN
{{- if $hasHTTPSocket }} if local-offload{{ end }}
http-request del-header {{ $global.SSL.HeadersPrefix }}-Client-DN
{{- if $hasHTTPSocket }} if local-offload{{ end }}
http-request del-header {{ $global.SSL.HeadersPrefix }}-Client-SHA1
{{- if $hasHTTPSocket }} if local-offload{{ end }}
http-request del-header {{ $global.SSL.HeadersPrefix }}-Client-Cert
{{- if $hasHTTPSocket }} if local-offload{{ end }}
{{- /*------------------------------------*/}}
{{- if $frontend.HasMaxBody }}
http-request set-var(req.maxbody) var(req.base),map_beg_int({{ $frontend.MaxBodySizeMap.MatchFile }},0)
{{- end }}
{{- /*------------------------------------*/}}
{{- if $frontend.HasTLSAuth }}
{{- $mandatory := $frontend.HasTLSMandatory }}
acl tls-has-crt ssl_c_used
{{- if $mandatory }}
acl tls-need-crt ssl_fc_sni -i -f {{ $frontend.TLSNoCrtErrorList.MatchFile }}
{{- if $frontend.TLSNoCrtErrorList.HasRegex }}
acl tls-need-crt ssl_fc_sni -i -m reg -f {{ $frontend.TLSNoCrtErrorList.RegexFile }}
{{- end }}
{{- end }}
acl tls-host-need-crt var(req.host) -i -f {{ $frontend.TLSNoCrtErrorList.MatchFile }}
{{- if $frontend.TLSNoCrtErrorList.HasRegex }}
acl tls-host-need-crt var(req.host) -i -m reg -f {{ $frontend.TLSNoCrtErrorList.RegexFile }}
{{- end }}
acl tls-has-invalid-crt ssl_c_ca_err gt 0
acl tls-has-invalid-crt ssl_c_err gt 0
acl tls-check-crt ssl_fc_sni -i -f {{ $frontend.TLSInvalidCrtErrorList.MatchFile }}
{{- if $frontend.TLSInvalidCrtErrorList.HasRegex }}
acl tls-check-crt ssl_fc_sni -i -m reg -f {{ $frontend.TLSInvalidCrtErrorList.RegexFile }}
{{- end }}
http-request set-var(req.snibase) ssl_fc_sni,concat(path),lower,regsub(:[0-9]+/,/)
{{- if $hasHTTPSocket }} if local-offload{{ end }}
{{- if $frontend.SNIBackendsMap.HasRegex }}
http-request set-var(req.snibackend) var(req.snibase)
{{- "" }},map_beg({{ $frontend.SNIBackendsMap.MatchFile }},_nomatch)
{{- if $hasHTTPSocket }} if local-offload{{ end }}
http-request set-var(req.snibackend) var(req.snibase)
{{- "" }},map_reg({{ $frontend.SNIBackendsMap.RegexFile }},_nomatch)
{{- "" }} if{{ if $hasHTTPSocket }} local-offload{{ end }}
{{- "" }} { var(req.snibackend) _nomatch }
http-request set-var(req.snibackend) var(req.base)
{{- "" }},map_beg({{ $frontend.SNIBackendsMap.MatchFile }},_nomatch)
{{- "" }} if{{ if $hasHTTPSocket }} local-offload{{ end }}
{{- "" }} { var(req.snibackend) _nomatch }
{{- "" }} !tls-has-crt !tls-host-need-crt
http-request set-var(req.snibackend) var(req.base)
{{- "" }},map_reg({{ $frontend.SNIBackendsMap.RegexFile }},_nomatch)
{{- "" }} if{{ if $hasHTTPSocket }} local-offload{{ end }}
{{- "" }} { var(req.snibackend) _nomatch }
{{- "" }} !tls-has-crt !tls-host-need-crt
{{- else }}
http-request set-var(req.snibackend) var(req.snibase)
{{- "" }},map_beg({{ $frontend.SNIBackendsMap.MatchFile }},_nomatch)
{{- if $hasHTTPSocket }} if local-offload{{ end }}
http-request set-var(req.snibackend) var(req.base)
{{- "" }},map_beg({{ $frontend.SNIBackendsMap.MatchFile }},_nomatch)
{{- "" }} if{{ if $hasHTTPSocket }} local-offload{{ end }}
{{- "" }} { var(req.snibackend) _nomatch }
{{- "" }} !tls-has-crt !tls-host-need-crt
{{- end }}
{{- if $mandatory }}
http-request set-var(req.tls_nocrt_redir) ssl_fc_sni,lower
{{- "" }},map({{ $frontend.TLSNoCrtErrorPagesMap.MatchFile }},_internal)
{{- "" }} if{{ if $hasHTTPSocket }} local-offload{{ end }}
{{- "" }} !tls-has-crt tls-need-crt
{{- if $frontend.TLSNoCrtErrorPagesMap.HasRegex }}
http-request set-var(req.tls_nocrt_redir) ssl_fc_sni,lower
{{- "" }},map_reg({{ $frontend.TLSNoCrtErrorPagesMap.RegexFile }},_internal)
{{- "" }} if{{ if $hasHTTPSocket }} local-offload{{ end }}
{{- "" }} { var(req.tls_nocrt_redir) _internal }
{{- end }}
{{- end }}
http-request set-var(req.tls_invalidcrt_redir) ssl_fc_sni,lower
{{- "" }},map({{ $frontend.TLSInvalidCrtErrorPagesMap.MatchFile }},_internal)
{{- "" }} if{{ if $hasHTTPSocket }} local-offload{{ end }}
{{- "" }} tls-has-invalid-crt tls-check-crt
{{- if $frontend.TLSInvalidCrtErrorPagesMap.HasRegex }}
http-request set-var(req.tls_invalidcrt_redir) ssl_fc_sni,lower
{{- "" }},map_reg({{ $frontend.TLSInvalidCrtErrorPagesMap.RegexFile }},_internal)
{{- "" }} if{{ if $hasHTTPSocket }} local-offload{{ end }}
{{- "" }} { var(req.tls_invalidcrt_redir) _internal }
{{- end }}
{{- if and $mandatory $frontend.HasNoCrtErrorPage }}
http-request redirect location %[var(req.tls_nocrt_redir)] code 303
{{- "" }} if{{ if $hasHTTPSocket }} local-offload{{ end }}
{{- "" }} { var(req.tls_nocrt_redir) -m found } !{ var(req.tls_nocrt_redir) _internal }
{{- end }}
{{- if $frontend.HasInvalidErrorPage }}
http-request redirect location %[var(req.tls_invalidcrt_redir)] code 303
{{- "" }} if{{ if $hasHTTPSocket }} local-offload{{ end }}
{{- "" }} { var(req.tls_invalidcrt_redir) -m found } !{ var(req.tls_invalidcrt_redir) _internal }
{{- end }}
{{- end }}
{{- /*------------------------------------*/}}
{{- range $snippet := $global.CustomFrontend }}
{{ $snippet }}
{{- end }}
{{- /*------------------------------------*/}}
{{- if $frontend.HasMaxBody }}
use_backend _error413 if
{{- "" }} !{ var(req.maxbody) 0 } { req.body_size,sub(req.maxbody) gt 0 }
{{- end }}
{{- if $frontend.HasTLSAuth }}
use_backend _error421 if
{{- "" }} { ssl_fc_has_sni } !{ ssl_fc_sni,strcmp(req.host) eq 0 }
{{- if $frontend.HasTLSMandatory }}
use_backend _error496 if
{{- "" }} { var(req.tls_nocrt_redir) _internal }
{{- end }}
use_backend _error495 if
{{- "" }} { var(req.tls_invalidcrt_redir) _internal }
{{- end }}
{{- /*------------------------------------*/}}
use_backend %[var(req.hostbackend)] unless { var(req.hostbackend) _nomatch }
{{- if $frontend.HasTLSAuth }}
use_backend %[var(req.snibackend)]
{{- if $hasHTTPSocket }} if local-offload !{ var(req.snibackend) _nomatch }
{{- else }} unless { var(req.snibackend) _nomatch }{{ end }}
{{- end }}
{{- template "defaultbackend" map $cfg }}
{{- end }}
{{- end }}{{/* if $fgroup */}}
{{- /*------------------------------------*/}}
{{- /*------------------------------------*/}}
{{- define "defaultbackend" }}
{{- $cfg := .p1 }}
{{- if $cfg.DefaultHost }}
{{- range $path := $cfg.DefaultHost.Paths }}
use_backend {{ $path.Backend.ID }}
{{- if ne $path.Path "/" }} if { path_beg {{ $path.Path }} }{{ end }}
{{- end }}
{{- end }}
{{- if $cfg.DefaultBackend }}
default_backend {{ $cfg.DefaultBackend.ID }}
{{- else }}
default_backend _error404
{{- end }}
{{- end }}
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# # SUPPORT
# #
#
# # # # # # # # # # # # # # # # # # #
# #
# Stats
#
listen stats
mode http
bind {{ $global.Stats.BindIP }}:{{ $global.Stats.Port }}
{{- if $global.Stats.TLSFilename }} ssl crt {{ $global.Stats.TLSFilename }}{{ end }}
{{- if $global.Stats.AcceptProxy }} accept-proxy{{ end }}
{{- if gt $global.Procs.Nbproc 1 }} process 1{{ end }}
{{- if $global.Stats.Auth }}
stats realm HAProxy\ Statistics
stats auth {{ $global.Stats.Auth }}
{{- end }}
stats enable