Skip to content

Commit 5857b2e

Browse files
committed
add nginx config
1 parent 2fd42c8 commit 5857b2e

File tree

1 file changed

+226
-0
lines changed

1 file changed

+226
-0
lines changed

nginx.conf.sigil

Lines changed: 226 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,226 @@
1+
limit_req_zone $binary_remote_addr zone=iplimit:10m rate=10r/m;
2+
3+
{{ range $port_map := .PROXY_PORT_MAP | split " " }}
4+
{{ $port_map_list := $port_map | split ":" }}
5+
{{ $scheme := index $port_map_list 0 }}
6+
{{ $listen_port := index $port_map_list 1 }}
7+
{{ $upstream_port := index $port_map_list 2 }}
8+
9+
{{ if eq $scheme "http" }}
10+
server {
11+
listen [{{ $.NGINX_BIND_ADDRESS_IP6 }}]:{{ $listen_port }};
12+
listen {{ if $.NGINX_BIND_ADDRESS_IP4 }}{{ $.NGINX_BIND_ADDRESS_IP4 }}:{{end}}{{ $listen_port }};
13+
{{ if $.NOSSL_SERVER_NAME }}server_name {{ $.NOSSL_SERVER_NAME }}; {{ end }}
14+
access_log {{ $.NGINX_ACCESS_LOG_PATH }}{{ if and ($.NGINX_ACCESS_LOG_FORMAT) (ne $.NGINX_ACCESS_LOG_PATH "off") }} {{ $.NGINX_ACCESS_LOG_FORMAT }}{{ end }};
15+
error_log {{ $.NGINX_ERROR_LOG_PATH }};
16+
underscores_in_headers {{ $.NGINX_UNDERSCORE_IN_HEADERS }};
17+
18+
{{ if $.CLIENT_BODY_TIMEOUT }}client_body_timeout {{ $.CLIENT_BODY_TIMEOUT }};{{end}}
19+
{{ if $.CLIENT_HEADER_TIMEOUT }}client_header_timeout {{ $.CLIENT_HEADER_TIMEOUT }};{{end}}
20+
{{ if $.KEEPALIVE_TIMEOUT }}keepalive_timeout {{ $.KEEPALIVE_TIMEOUT }};{{end}}
21+
{{ if $.LINGERING_TIMEOUT }}lingering_timeout {{ $.LINGERING_TIMEOUT }};{{end}}
22+
{{ if $.SEND_TIMEOUT }}send_timeout {{ $.SEND_TIMEOUT }};{{end}}
23+
24+
{{ if (and (eq $listen_port "80") ($.SSL_INUSE)) }}
25+
include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf;
26+
location / {
27+
return 301 https://$host:{{ $.PROXY_SSL_PORT }}$request_uri;
28+
}
29+
{{ else }}
30+
location / {
31+
32+
gzip on;
33+
gzip_min_length 1100;
34+
gzip_buffers 4 32k;
35+
gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/wasm application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml;
36+
gzip_vary on;
37+
gzip_comp_level 6;
38+
39+
proxy_pass http://{{ $.APP }}-{{ $upstream_port }};
40+
proxy_http_version 1.1;
41+
{{ if $.PROXY_CONNECT_TIMEOUT }}proxy_connect_timeout {{ $.PROXY_CONNECT_TIMEOUT }};{{end}}
42+
{{ if $.PROXY_READ_TIMEOUT }}proxy_read_timeout {{ $.PROXY_READ_TIMEOUT }};{{end}}
43+
{{ if $.PROXY_SEND_TIMEOUT }}proxy_send_timeout {{ $.PROXY_SEND_TIMEOUT }};{{end}}
44+
proxy_buffer_size {{ $.PROXY_BUFFER_SIZE }};
45+
proxy_buffering {{ $.PROXY_BUFFERING }};
46+
proxy_buffers {{ $.PROXY_BUFFERS }};
47+
proxy_busy_buffers_size {{ $.PROXY_BUSY_BUFFERS_SIZE }};
48+
proxy_set_header Upgrade $http_upgrade;
49+
proxy_set_header Connection $http_connection;
50+
proxy_set_header Host $http_host;
51+
proxy_set_header X-Forwarded-For {{ $.PROXY_X_FORWARDED_FOR }};
52+
proxy_set_header X-Forwarded-Port {{ $.PROXY_X_FORWARDED_PORT }};
53+
proxy_set_header X-Forwarded-Proto {{ $.PROXY_X_FORWARDED_PROTO }};
54+
proxy_set_header X-Request-Start $msec;
55+
{{ if $.PROXY_X_FORWARDED_SSL }}proxy_set_header X-Forwarded-Ssl {{ $.PROXY_X_FORWARDED_SSL }};{{ end }}
56+
}
57+
58+
{{ if $.CLIENT_MAX_BODY_SIZE }}client_max_body_size {{ $.CLIENT_MAX_BODY_SIZE }};{{ end }}
59+
60+
error_page 400 401 402 403 405 406 407 408 409 410 411 412 413 414 415 416 417 418 420 422 423 424 426 428 429 431 444 449 450 451 /400-error.html;
61+
location /400-error.html {
62+
root {{ $.DOKKU_LIB_ROOT }}/data/nginx-vhosts/dokku-errors;
63+
internal;
64+
}
65+
66+
error_page 404 /404-error.html;
67+
location /404-error.html {
68+
root {{ $.DOKKU_LIB_ROOT }}/data/nginx-vhosts/dokku-errors;
69+
internal;
70+
}
71+
72+
error_page 500 501 502 503 504 505 506 507 508 509 510 511 /500-error.html;
73+
location /500-error.html {
74+
root {{ $.DOKKU_LIB_ROOT }}/data/nginx-vhosts/dokku-errors;
75+
internal;
76+
}
77+
include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf;
78+
{{ end }}
79+
}
80+
{{ else if eq $scheme "https"}}
81+
server {
82+
{{ if eq $.HTTP2_DIRECTIVE_SUPPORTED "true" }}
83+
listen [{{ $.NGINX_BIND_ADDRESS_IP6 }}]:{{ $listen_port }} ssl;
84+
listen {{ if $.NGINX_BIND_ADDRESS_IP4 }}{{ $.NGINX_BIND_ADDRESS_IP4 }}:{{end}}{{ $listen_port }} ssl;
85+
http2 on;
86+
{{ else }}
87+
listen [{{ $.NGINX_BIND_ADDRESS_IP6 }}]:{{ $listen_port }} ssl {{ if eq $.HTTP2_SUPPORTED "true" }}http2{{ end }};
88+
listen {{ if $.NGINX_BIND_ADDRESS_IP4 }}{{ $.NGINX_BIND_ADDRESS_IP4 }}:{{end}}{{ $listen_port }} ssl {{ if eq $.HTTP2_SUPPORTED "true" }}http2{{ end }};
89+
{{ end }}
90+
{{ if $.SSL_SERVER_NAME }}server_name {{ $.SSL_SERVER_NAME }}; {{ end }}
91+
{{ if $.NOSSL_SERVER_NAME }}server_name {{ $.NOSSL_SERVER_NAME }}; {{ end }}
92+
access_log {{ $.NGINX_ACCESS_LOG_PATH }}{{ if and ($.NGINX_ACCESS_LOG_FORMAT) (ne $.NGINX_ACCESS_LOG_PATH "off") }} {{ $.NGINX_ACCESS_LOG_FORMAT }}{{ end }};
93+
error_log {{ $.NGINX_ERROR_LOG_PATH }};
94+
underscores_in_headers {{ $.NGINX_UNDERSCORE_IN_HEADERS }};
95+
96+
ssl_certificate {{ $.APP_SSL_PATH }}/server.crt;
97+
ssl_certificate_key {{ $.APP_SSL_PATH }}/server.key;
98+
ssl_protocols TLSv1.2 {{ if eq $.TLS13_SUPPORTED "true" }}TLSv1.3{{ end }};
99+
ssl_prefer_server_ciphers off;
100+
101+
{{ if $.CLIENT_BODY_TIMEOUT }}client_body_timeout {{ $.CLIENT_BODY_TIMEOUT }};{{end}}
102+
{{ if $.CLIENT_HEADER_TIMEOUT }}client_header_timeout {{ $.CLIENT_HEADER_TIMEOUT }};{{end}}
103+
{{ if $.KEEPALIVE_TIMEOUT }}keepalive_timeout {{ $.KEEPALIVE_TIMEOUT }};{{end}}
104+
{{ if $.LINGERING_TIMEOUT }}lingering_timeout {{ $.LINGERING_TIMEOUT }};{{end}}
105+
{{ if $.SEND_TIMEOUT }}send_timeout {{ $.SEND_TIMEOUT }};{{end}}
106+
107+
location / {
108+
109+
gzip on;
110+
gzip_min_length 1100;
111+
gzip_buffers 4 32k;
112+
gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml font/truetype application/x-font-ttf font/opentype application/vnd.ms-fontobject image/svg+xml;
113+
gzip_vary on;
114+
gzip_comp_level 6;
115+
116+
proxy_pass http://{{ $.APP }}-{{ $upstream_port }};
117+
{{ if eq $.HTTP2_PUSH_SUPPORTED "true" }}http2_push_preload on; {{ end }}
118+
proxy_http_version 1.1;
119+
{{ if $.PROXY_CONNECT_TIMEOUT }}proxy_connect_timeout {{ $.PROXY_CONNECT_TIMEOUT }};{{end}}
120+
{{ if $.PROXY_READ_TIMEOUT }}proxy_read_timeout {{ $.PROXY_READ_TIMEOUT }};{{end}}
121+
{{ if $.PROXY_SEND_TIMEOUT }}proxy_send_timeout {{ $.PROXY_SEND_TIMEOUT }};{{end}}
122+
proxy_buffer_size {{ $.PROXY_BUFFER_SIZE }};
123+
proxy_buffering {{ $.PROXY_BUFFERING }};
124+
proxy_buffers {{ $.PROXY_BUFFERS }};
125+
proxy_busy_buffers_size {{ $.PROXY_BUSY_BUFFERS_SIZE }};
126+
proxy_set_header Upgrade $http_upgrade;
127+
proxy_set_header Connection $http_connection;
128+
proxy_set_header Host $http_host;
129+
proxy_set_header X-Forwarded-For {{ $.PROXY_X_FORWARDED_FOR }};
130+
proxy_set_header X-Forwarded-Port {{ $.PROXY_X_FORWARDED_PORT }};
131+
proxy_set_header X-Forwarded-Proto {{ $.PROXY_X_FORWARDED_PROTO }};
132+
proxy_set_header X-Request-Start $msec;
133+
{{ if $.PROXY_X_FORWARDED_SSL }}proxy_set_header X-Forwarded-Ssl {{ $.PROXY_X_FORWARDED_SSL }};{{ end }}
134+
}
135+
136+
{{ if $.CLIENT_MAX_BODY_SIZE }}client_max_body_size {{ $.CLIENT_MAX_BODY_SIZE }};{{ end }}
137+
138+
error_page 400 401 402 403 405 406 407 408 409 410 411 412 413 414 415 416 417 418 420 422 423 424 426 428 429 431 444 449 450 451 /400-error.html;
139+
location /400-error.html {
140+
root {{ $.DOKKU_LIB_ROOT }}/data/nginx-vhosts/dokku-errors;
141+
internal;
142+
}
143+
144+
error_page 404 /404-error.html;
145+
location /404-error.html {
146+
root {{ $.DOKKU_LIB_ROOT }}/data/nginx-vhosts/dokku-errors;
147+
internal;
148+
}
149+
150+
error_page 500 501 503 504 505 506 507 508 509 510 511 /500-error.html;
151+
location /500-error.html {
152+
root {{ $.DOKKU_LIB_ROOT }}/data/nginx-vhosts/dokku-errors;
153+
internal;
154+
}
155+
156+
error_page 502 /502-error.html;
157+
location /502-error.html {
158+
root {{ $.DOKKU_LIB_ROOT }}/data/nginx-vhosts/dokku-errors;
159+
internal;
160+
}
161+
include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf;
162+
}
163+
{{ else if eq $scheme "grpc"}}
164+
{{ if eq $.GRPC_SUPPORTED "true"}}{{ if eq $.HTTP2_SUPPORTED "true"}}
165+
server {
166+
{{ if eq $.HTTP2_DIRECTIVE_SUPPORTED "true" }}
167+
listen [{{ $.NGINX_BIND_ADDRESS_IP6 }}]:{{ $listen_port }};
168+
listen {{ if $.NGINX_BIND_ADDRESS_IP4 }}{{ $.NGINX_BIND_ADDRESS_IP4 }}:{{end}}{{ $listen_port }};
169+
http2 on;
170+
{{ else }}
171+
listen [{{ $.NGINX_BIND_ADDRESS_IP6 }}]:{{ $listen_port }} http2;
172+
listen {{ if $.NGINX_BIND_ADDRESS_IP4 }}{{ $.NGINX_BIND_ADDRESS_IP4 }}:{{end}}{{ $listen_port }} http2;
173+
{{ end }}
174+
{{ if $.NOSSL_SERVER_NAME }}server_name {{ $.NOSSL_SERVER_NAME }}; {{ end }}
175+
access_log {{ $.NGINX_ACCESS_LOG_PATH }}{{ if and ($.NGINX_ACCESS_LOG_FORMAT) (ne $.NGINX_ACCESS_LOG_PATH "off") }} {{ $.NGINX_ACCESS_LOG_FORMAT }}{{ end }};
176+
error_log {{ $.NGINX_ERROR_LOG_PATH }};
177+
underscores_in_headers {{ $.NGINX_UNDERSCORE_IN_HEADERS }};
178+
location / {
179+
grpc_pass grpc://{{ $.APP }}-{{ $upstream_port }};
180+
}
181+
182+
{{ if $.CLIENT_MAX_BODY_SIZE }}client_max_body_size {{ $.CLIENT_MAX_BODY_SIZE }};{{ end }}
183+
include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf;
184+
}
185+
{{ end }}{{ end }}
186+
{{ else if eq $scheme "grpcs"}}
187+
{{ if eq $.GRPC_SUPPORTED "true"}}{{ if eq $.HTTP2_SUPPORTED "true"}}
188+
server {
189+
{{ if eq $.HTTP2_DIRECTIVE_SUPPORTED "true" }}
190+
listen [{{ $.NGINX_BIND_ADDRESS_IP6 }}]:{{ $listen_port }} ssl;
191+
listen {{ if $.NGINX_BIND_ADDRESS_IP4 }}{{ $.NGINX_BIND_ADDRESS_IP4 }}:{{end}}{{ $listen_port }} ssl;
192+
http2 on;
193+
{{ else }}
194+
listen [{{ $.NGINX_BIND_ADDRESS_IP6 }}]:{{ $listen_port }} ssl http2;
195+
listen {{ if $.NGINX_BIND_ADDRESS_IP4 }}{{ $.NGINX_BIND_ADDRESS_IP4 }}:{{end}}{{ $listen_port }} ssl http2;
196+
{{ end }}
197+
{{ if $.NOSSL_SERVER_NAME }}server_name {{ $.NOSSL_SERVER_NAME }}; {{ end }}
198+
access_log {{ $.NGINX_ACCESS_LOG_PATH }}{{ if and ($.NGINX_ACCESS_LOG_FORMAT) (ne $.NGINX_ACCESS_LOG_PATH "off") }} {{ $.NGINX_ACCESS_LOG_FORMAT }}{{ end }};
199+
error_log {{ $.NGINX_ERROR_LOG_PATH }};
200+
underscores_in_headers {{ $.NGINX_UNDERSCORE_IN_HEADERS }};
201+
202+
ssl_certificate {{ $.APP_SSL_PATH }}/server.crt;
203+
ssl_certificate_key {{ $.APP_SSL_PATH }}/server.key;
204+
ssl_protocols TLSv1.2 {{ if eq $.TLS13_SUPPORTED "true" }}TLSv1.3{{ end }};
205+
ssl_prefer_server_ciphers off;
206+
207+
location / {
208+
grpc_pass grpc://{{ $.APP }}-{{ $upstream_port }};
209+
}
210+
211+
{{ if $.CLIENT_MAX_BODY_SIZE }}client_max_body_size {{ $.CLIENT_MAX_BODY_SIZE }};{{ end }}
212+
include {{ $.DOKKU_ROOT }}/{{ $.APP }}/nginx.conf.d/*.conf;
213+
}
214+
{{ end }}{{ end }}
215+
{{ end }}
216+
{{ end }}
217+
218+
{{ if $.DOKKU_APP_WEB_LISTENERS }}
219+
{{ range $upstream_port := $.PROXY_UPSTREAM_PORTS | split " " }}
220+
upstream {{ $.APP }}-{{ $upstream_port }} {
221+
{{ range $listeners := $.DOKKU_APP_WEB_LISTENERS | split " " }}
222+
{{ $listener_list := $listeners | split ":" }}
223+
{{ $listener_ip := index $listener_list 0 }}
224+
server {{ $listener_ip }}:{{ $upstream_port }};{{ end }}
225+
}
226+
{{ end }}{{ end }}

0 commit comments

Comments
 (0)