-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathnginx.conf
More file actions
301 lines (261 loc) · 11 KB
/
nginx.conf
File metadata and controls
301 lines (261 loc) · 11 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
# required to run in a container
daemon off;
user www-data;
worker_processes {{ or (.deis_router_workerProcesses) "auto" }};
pid /run/nginx.pid;
events {
worker_connections {{ or (.deis_router_maxWorkerConnections) "768" }};
# multi_accept on;
}
http {
# basic settings
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
server_names_hash_max_size {{ or (.deis_router_serverNameHashMaxSize) "512" }};
server_names_hash_bucket_size {{ or (.deis_router_serverNameHashBucketSize) "64" }};
include /opt/nginx/conf/mime.types;
default_type application/octet-stream;
{{ if .deis_router_gzip }}
gzip {{ .deis_router_gzip }};
gzip_comp_level {{ or .deis_router_gzipCompLevel "5" }};
gzip_disable {{ or .deis_router_gzipDisable "\"msie6\"" }};
gzip_http_version {{ or .deis_router_gzipHttpVersion "1.1" }};
gzip_min_length {{ or .deis_router_gzipMinLength "256" }};
gzip_types {{ or .deis_router_gzipTypes "application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/svg+xml image/x-icon text/css text/plain text/x-component" }};
gzip_proxied {{ or .deis_router_gzipProxied "any" }};
gzip_vary {{ or .deis_router_gzipVary "on" }};
{{ end }}
{{ $useFirewall := or .deis_router_firewall_enabled "false" }}{{ if eq $useFirewall "true" }}# include naxsi rules
include /opt/nginx/firewall/naxsi_core.rules;
include /opt/nginx/firewall/web_apps.rules;
include /opt/nginx/firewall/scanner.rules;
include /opt/nginx/firewall/web_server.rules;{{ end }}
{{ $firewallErrorCode := or (.deis_router_firewall_errorCode) "400" }}
client_max_body_size {{ or (.deis_router_bodySize) "1m" }};
log_format upstreaminfo '[$time_local] - $remote_addr - $remote_user - $status - "$request" - $bytes_sent - "$http_referer" - "$http_user_agent" - "$server_name" - $upstream_addr - $http_host - $upstream_response_time - $request_time';
# send logs to STDOUT so they can be seen using 'docker logs'
access_log /opt/nginx/logs/access.log upstreaminfo;
error_log /opt/nginx/logs/error.log;
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
# trust http_x_forwarded_proto headers correctly indicate ssl offloading
map $http_x_forwarded_proto $access_scheme {
default $http_x_forwarded_proto;
'' $scheme;
}
{{ $enforceHTTPS := or .deis_router_enforceHTTPS "false" }}
## start deis-controller
{{ if .deis_controller_host }}
upstream deis-controller {
server {{ .deis_controller_host }}:{{ .deis_controller_port }};
}
{{ end }}
server {
server_name ~^deis\.(?<domain>.+)$;
include deis.conf;
{{ if .deis_controller_host }}
location / {
{{ if eq $useFirewall "true" }}include /opt/nginx/firewall/active-mode.rules;{{ end }}
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_connect_timeout {{ or (.deis_router_controller_timeout_connect) "10s" }};
proxy_send_timeout {{ or (.deis_router_controller_timeout_send) "20m" }};
proxy_read_timeout {{ or (.deis_router_controller_timeout_read) "20m" }};
proxy_pass http://deis-controller;
}
{{ else }}
location / {
return 503;
}
{{ end }}
{{ if eq $useFirewall "true" }}location /RequestDenied {
return {{ $firewallErrorCode }};
}{{ end }}
{{ if eq $enforceHTTPS "true" }}
if ($access_scheme != "https") {
return 301 https://$host$request_uri;
}
{{ end }}
}
## end deis-controller
## start deis-store-gateway
{{ if .deis_store_gateway_host }}
upstream deis-store-gateway {
server {{ .deis_store_gateway_host }}:{{ .deis_store_gateway_port }};
}
{{ end }}
server {
server_name ~^deis-store\.(?<domain>.+)$;
include deis.conf;
client_max_body_size 0;
{{ if .deis_store_gateway_host }}
location / {
{{ if eq $useFirewall "true" }}include /opt/nginx/firewall/active-mode.rules;{{ end }}
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
proxy_connect_timeout 10s;
proxy_send_timeout 1200s;
proxy_read_timeout 1200s;
proxy_pass http://deis-store-gateway;
}
{{ else }}
location / {
return 503;
}
{{ end }}
}
## end deis-store-gateway
## start service definitions for each application
{{ $affinityArg := .deis_router_affinityArg }}
{{ $certs := .deis_certs }}
{{ $domains := .deis_domains }}
{{ range $service := .deis_services }}{{ if $service.Nodes }}
upstream {{ Base $service.Key }} {
{{ if $affinityArg }}hash $arg_{{ $affinityArg }} consistent;
{{ end }}
{{ range $upstream := $service.Nodes }}server {{ $upstream.Value }};
{{ end }}
}
{{ end }}
## server entries for custom domains
{{ range $domain := $domains }}{{ if eq (Base $service.Key) $domain.Value }}
server {
server_name {{ Base $domain.Key }};
server_name_in_redirect off;
port_in_redirect off;
listen 80;
{{/* if a SSL certificate is installed for this domain, use SSL */}}
{{/* Note (bacongobbler): domains are separate from the default platform domain, */}}
{{/* so we can't rely on deis.conf as each domain is an island */}}
{{ range $cert := $certs }}{{ if eq (Base $domain.Key) (Base $cert.Key) }}
listen 443 ssl spdy;
ssl_certificate /etc/ssl/deis/certs/{{ Base $domain.Key }}.cert;
ssl_certificate_key /etc/ssl/deis/keys/{{ Base $domain.Key }}.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
{{ end }}{{ end }}
{{ if $service.Nodes }}
location / {
{{ if eq $useFirewall "true" }}include /opt/nginx/firewall/active-mode.rules;{{ end }}
proxy_buffering off;
proxy_set_header Host $host;
set $access_ssl 'off';
set $access_port '80';
if ($access_scheme ~ https) {
set $access_ssl 'on';
set $access_port '443';
}
proxy_set_header X-Forwarded-Port $access_port;
proxy_set_header X-Forwarded-Proto $access_scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Ssl $access_ssl;
proxy_redirect off;
proxy_connect_timeout 30s;
proxy_send_timeout 1200s;
proxy_read_timeout 1200s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_next_upstream error timeout http_502 http_503 http_504;
{{ if eq $enforceHTTPS "true" }}
if ($access_scheme != "https") {
return 301 https://$host$request_uri;
}
{{ end }}
proxy_pass http://{{ Base $service.Key }};
}
{{ else }}
location / {
return 503;
}
{{ end }}
{{ if eq $useFirewall "true" }}location /RequestDenied {
return {{ $firewallErrorCode }};
}{{ end }}
}
{{ end }}{{ end }}
## end entries for custom domains
server {
server_name ~^{{ Base $service.Key }}\.(?<domain>.+)$;
include deis.conf;
{{ if $service.Nodes }}
location / {
{{ if eq $useFirewall "true" }}include /opt/nginx/firewall/active-mode.rules;{{ end }}
proxy_buffering off;
proxy_set_header Host $host;
set $access_ssl 'off';
set $access_port '80';
if ($access_scheme ~ https) {
set $access_ssl 'on';
set $access_port '443';
}
proxy_set_header X-Forwarded-Port $access_port;
proxy_set_header X-Forwarded-Proto $access_scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Ssl $access_ssl;
proxy_redirect off;
proxy_connect_timeout 30s;
proxy_send_timeout 1200s;
proxy_read_timeout 1200s;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
proxy_next_upstream error timeout http_502 http_503 http_504;
{{ if eq $enforceHTTPS "true" }}
if ($access_scheme != "https") {
return 301 https://$host$request_uri;
}
{{ end }}
proxy_pass http://{{ Base $service.Key }};
}
{{ else }}
location / {
return 503;
}
{{ end }}
{{ if eq $useFirewall "true" }}location /RequestDenied {
return {{ $firewallErrorCode }};
}{{ end }}
}
{{ end }}
## end service definitions for each application
# healthcheck
server {
listen 80 default_server;
location /health-check {
default_type 'text/plain';
access_log off;
return 200;
}
location /router-nginx-status {
stub_status on;
}
}
}
## start builder
{{ if .deis_builder_host }}
tcp {
access_log /opt/nginx/logs/git.log;
tcp_nodelay on;
timeout {{ or (.deis_router_builder_timeout_tcp) "1200000" }};
# same directive names, but these are in miliseconds...
proxy_connect_timeout {{ or (.deis_router_builder_timeout_connect) "10000" }};
proxy_send_timeout {{ or (.deis_router_builder_timeout_send) "1200000" }};
proxy_read_timeout {{ or (.deis_router_builder_timeout_read) "1200000" }};
upstream builder {
server {{ .deis_builder_host }}:{{ .deis_builder_port }};
}
server {
listen 2222;
proxy_pass builder;
}
}{{ end }}
## end builder