-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathnginx-plus.virtualserver.tmpl
146 lines (121 loc) · 4.3 KB
/
nginx-plus.virtualserver.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
{{ range $u := .Upstreams }}
upstream {{ $u.Name }} {
zone {{ $u.Name }} {{ $u.UpstreamZoneSize }};
{{ if $u.LBMethod }}{{ $u.LBMethod }};{{ end }}
{{ range $s := $u.Servers }}
server {{ $s.Address }} max_fails={{ $s.MaxFails }} fail_timeout={{ $s.FailTimeout }} max_conns={{ $s.MaxConns }}{{ if $s.Resolve }} resolve{{ end }};
{{ end }}
{{ if $u.Keepalive }}
keepalive {{ $u.Keepalive }};
{{ end }}
}
{{ end }}
{{ range $sc := .SplitClients }}
split_clients {{ $sc.Source }} {{ $sc.Variable }} {
{{ range $d := $sc.Distributions }}
{{ $d.Weight }} {{ $d.Value }};
{{ end }}
}
{{ end }}
{{ range $m := .Maps }}
map {{ $m.Source }} {{ $m.Variable }} {
{{ range $p := $m.Parameters }}
{{ $p.Value }} {{ $p.Result }};
{{ end }}
}
{{ end }}
{{ range $m := .StatusMatches }}
match {{ $m.Name }} {
status {{ $m.Code }};
}
{{ end }}
{{ $s := .Server }}
server {
listen 80{{ if $s.ProxyProtocol }} proxy_protocol{{ end }};
server_name {{ $s.ServerName }};
{{ with $ssl := $s.SSL }}
listen 443 ssl{{ if $ssl.HTTP2 }} http2{{ end }}{{ if $s.ProxyProtocol }} proxy_protocol{{ end }};
ssl_certificate {{ $ssl.Certificate }};
ssl_certificate_key {{ $ssl.CertificateKey }};
{{ if $ssl.Ciphers }}
ssl_ciphers {{ $ssl.Ciphers }};
{{ end }}
{{ if $ssl.RedirectToHTTPS }}
if ($scheme = http) {
return 301 https://$host$request_uri;
}
{{ end }}
{{ end }}
{{ if $s.RedirectToHTTPSBasedOnXForwarderProto }}
if ($http_x_forwarded_proto = 'http') {
return 301 https://$host$request_uri;
}
{{ end }}
server_tokens "{{ $s.ServerTokens }}";
{{ range $setRealIPFrom := $s.SetRealIPFrom }}
set_real_ip_from {{ $setRealIPFrom }};
{{ end }}
{{ if $s.RealIPHeader }}
real_ip_header {{ $s.RealIPHeader }};
{{ end }}
{{ if $s.RealIPRecursive }}
real_ip_recursive on;
{{ end }}
{{ range $snippet := $s.Snippets }}
{{ $snippet }}
{{ end }}
{{ range $l := $s.InternalRedirectLocations }}
location {{ $l.Path }} {
error_page 418 = {{ $l.Destination }};
return 418;
}
{{ end }}
{{ range $hc := $s.HealthChecks }}
location @hc-{{ $hc.Name }} {
{{ range $n, $v := $hc.Headers }}
proxy_set_header {{ $n }} "{{ $v }}";
{{ end }}
proxy_connect_timeout {{ $hc.ProxyConnectTimeout }};
proxy_read_timeout {{ $hc.ProxyReadTimeout }};
proxy_send_timeout {{ $hc.ProxySendTimeout }};
proxy_pass {{ $hc.ProxyPass }};
health_check uri={{ $hc.URI }} port={{ $hc.Port }} interval={{ $hc.Interval }} jitter={{ $hc.Jitter }}
fails={{ $hc.Fails }} passes={{ $hc.Passes }}{{ if $hc.Match }} match={{ $hc.Match }}{{ end }};
}
{{ end }}
{{ range $l := $s.Locations }}
location {{ $l.Path }} {
{{ range $snippet := $l.Snippets }}
{{ $snippet }}
{{ end }}
proxy_connect_timeout {{ $l.ProxyConnectTimeout }};
proxy_read_timeout {{ $l.ProxyReadTimeout }};
proxy_send_timeout {{ $l.ProxySendTimeout }};
client_max_body_size {{ $l.ClientMaxBodySize }};
{{ if $l.ProxyMaxTempFileSize }}
proxy_max_temp_file_size {{ $l.ProxyMaxTempFileSize }};
{{ end }}
proxy_buffering {{ if $l.ProxyBuffering }}on{{ else }}off{{ end }};
{{ if $l.ProxyBuffers }}
proxy_buffers {{ $l.ProxyBuffers }};
{{ end }}
{{ if $l.ProxyBufferSize }}
proxy_buffer_size {{ $l.ProxyBufferSize }};
{{ end }}
proxy_http_version 1.1;
set $default_connection_header {{ if $l.HasKeepalive }}""{{ else }}close{{ end }};
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $vs_connection_header;
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-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass {{ $l.ProxyPass }};
proxy_next_upstream {{ $l.ProxyNextUpstream }};
proxy_next_upstream_timeout {{ $l.ProxyNextUpstreamTimeout }};
proxy_next_upstream_tries {{ $l.ProxyNextUpstreamTries }};
}
{{ end }}
}