nginx.tmpl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. {{ $CurrentContainer := where $ "ID" .Docker.CurrentContainerID | first }}
  2. {{ define "upstream" }}
  3. {{ if .Address }}
  4. {{/* If we got the containers from swarm and this container's port is published to host, use host IP:PORT */}}
  5. {{ if and .Container.Node.ID .Address.HostPort }}
  6. # {{ .Container.Node.Name }}/{{ .Container.Name }}
  7. server {{ .Container.Node.Address.IP }}:{{ .Address.HostPort }};
  8. {{/* If there is no swarm node or the port is not published on host, use container's IP:PORT */}}
  9. {{ else if .Network }}
  10. # {{ .Container.Name }}
  11. server {{ .Network.IP }}:{{ .Address.Port }};
  12. {{ end }}
  13. {{ else if .Network }}
  14. # {{ .Container.Name }}
  15. {{ if .Network.IP }}
  16. server {{ .Network.IP }} down;
  17. {{ else }}
  18. server 127.0.0.1 down;
  19. {{ end }}
  20. {{ end }}
  21. {{ end }}
  22. {{ define "ssl_policy" }}
  23. {{ if eq .ssl_policy "Mozilla-Modern" }}
  24. ssl_protocols TLSv1.3;
  25. {{/* nginx currently lacks ability to choose ciphers in TLS 1.3 in configuration, see https://trac.nginx.org/nginx/ticket/1529 /*}}
  26. {{/* a possible workaround can be modify /etc/ssl/openssl.cnf to change it globally (see https://trac.nginx.org/nginx/ticket/1529#comment:12 ) /*}}
  27. {{/* explicitly set ngnix default value in order to allow single servers to override the global http value */}}
  28. ssl_ciphers HIGH:!aNULL:!MD5;
  29. ssl_prefer_server_ciphers off;
  30. {{ else if eq .ssl_policy "Mozilla-Intermediate" }}
  31. ssl_protocols TLSv1.2 TLSv1.3;
  32. ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384';
  33. ssl_prefer_server_ciphers off;
  34. {{ else if eq .ssl_policy "Mozilla-Old" }}
  35. ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  36. ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA256:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA';
  37. ssl_prefer_server_ciphers on;
  38. {{ else if eq .ssl_policy "AWS-TLS-1-2-2017-01" }}
  39. ssl_protocols TLSv1.2 TLSv1.3;
  40. ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:AES128-GCM-SHA256:AES128-SHA256:AES256-GCM-SHA384:AES256-SHA256';
  41. ssl_prefer_server_ciphers on;
  42. {{ else if eq .ssl_policy "AWS-TLS-1-1-2017-01" }}
  43. ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
  44. ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA';
  45. ssl_prefer_server_ciphers on;
  46. {{ else if eq .ssl_policy "AWS-2016-08" }}
  47. ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  48. ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA';
  49. ssl_prefer_server_ciphers on;
  50. {{ else if eq .ssl_policy "AWS-2015-05" }}
  51. ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  52. ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:DES-CBC3-SHA';
  53. ssl_prefer_server_ciphers on;
  54. {{ else if eq .ssl_policy "AWS-2015-03" }}
  55. ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  56. ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:DHE-DSS-AES128-SHA:DES-CBC3-SHA';
  57. ssl_prefer_server_ciphers on;
  58. {{ else if eq .ssl_policy "AWS-2015-02" }}
  59. ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
  60. ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:AES128-GCM-SHA256:AES128-SHA256:AES128-SHA:AES256-GCM-SHA384:AES256-SHA256:AES256-SHA:DHE-DSS-AES128-SHA';
  61. ssl_prefer_server_ciphers on;
  62. {{ end }}
  63. {{ end }}
  64. # If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the
  65. # scheme used to connect to this server
  66. map $http_x_forwarded_proto $proxy_x_forwarded_proto {
  67. default $http_x_forwarded_proto;
  68. '' $scheme;
  69. }
  70. # If we receive X-Forwarded-Port, pass it through; otherwise, pass along the
  71. # server port the client connected to
  72. map $http_x_forwarded_port $proxy_x_forwarded_port {
  73. default $http_x_forwarded_port;
  74. '' $server_port;
  75. }
  76. # If we receive Upgrade, set Connection to "upgrade"; otherwise, delete any
  77. # Connection header that may have been passed to this server
  78. map $http_upgrade $proxy_connection {
  79. default upgrade;
  80. '' close;
  81. }
  82. # Apply fix for very long server names
  83. server_names_hash_bucket_size 128;
  84. # Default dhparam
  85. {{ if (exists "/etc/nginx/dhparam/dhparam.pem") }}
  86. ssl_dhparam /etc/nginx/dhparam/dhparam.pem;
  87. {{ end }}
  88. # Set appropriate X-Forwarded-Ssl header
  89. map $scheme $proxy_x_forwarded_ssl {
  90. default off;
  91. https on;
  92. }
  93. gzip_types text/plain text/css application/javascript application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
  94. log_format vhost '$host $remote_addr - $remote_user [$time_local] '
  95. '"$request" $status $body_bytes_sent '
  96. '"$http_referer" "$http_user_agent"';
  97. access_log off;
  98. {{/* Get the SSL_POLICY defined by this container, falling back to "Mozilla-Intermediate" */}}
  99. {{ $ssl_policy := or ($.Env.SSL_POLICY) "Mozilla-Intermediate" }}
  100. {{ template "ssl_policy" (dict "ssl_policy" $ssl_policy) }}
  101. {{ if $.Env.RESOLVERS }}
  102. resolver {{ $.Env.RESOLVERS }};
  103. {{ end }}
  104. {{ if (exists "/etc/nginx/proxy.conf") }}
  105. include /etc/nginx/proxy.conf;
  106. {{ else }}
  107. # HTTP 1.1 support
  108. proxy_http_version 1.1;
  109. proxy_buffering off;
  110. proxy_set_header Host $http_host;
  111. proxy_set_header Upgrade $http_upgrade;
  112. proxy_set_header Connection $proxy_connection;
  113. proxy_set_header X-Real-IP $remote_addr;
  114. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  115. proxy_set_header X-Forwarded-Proto $proxy_x_forwarded_proto;
  116. proxy_set_header X-Forwarded-Ssl $proxy_x_forwarded_ssl;
  117. proxy_set_header X-Forwarded-Port $proxy_x_forwarded_port;
  118. # Mitigate httpoxy attack (see README for details)
  119. proxy_set_header Proxy "";
  120. {{ end }}
  121. {{ $enable_ipv6 := eq (or ($.Env.ENABLE_IPV6) "") "true" }}
  122. server {
  123. server_name _; # This is just an invalid value which will never trigger on a real hostname.
  124. listen 80;
  125. {{ if $enable_ipv6 }}
  126. listen [::]:80;
  127. {{ end }}
  128. access_log /var/log/nginx/access.log vhost;
  129. return 503;
  130. }
  131. {{ if (and (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
  132. server {
  133. server_name _; # This is just an invalid value which will never trigger on a real hostname.
  134. listen 443 ssl http2;
  135. {{ if $enable_ipv6 }}
  136. listen [::]:443 ssl http2;
  137. {{ end }}
  138. access_log /var/log/nginx/access.log vhost;
  139. return 503;
  140. ssl_session_cache shared:SSL:50m;
  141. ssl_session_tickets off;
  142. ssl_certificate /etc/nginx/certs/default.crt;
  143. ssl_certificate_key /etc/nginx/certs/default.key;
  144. }
  145. {{ end }}
  146. {{ range $host, $containers := groupByMulti $ "Env.VIRTUAL_HOST" "," }}
  147. {{ $host := trim $host }}
  148. {{ $is_regexp := hasPrefix "~" $host }}
  149. {{ $upstream_name := when $is_regexp (sha1 $host) $host }}
  150. # {{ $host }}
  151. upstream {{ $upstream_name }} {
  152. {{ range $container := $containers }}
  153. {{ $addrLen := len $container.Addresses }}
  154. {{ range $knownNetwork := $CurrentContainer.Networks }}
  155. {{ range $containerNetwork := $container.Networks }}
  156. {{ if (and (ne $containerNetwork.Name "ingress") (or (eq $knownNetwork.Name $containerNetwork.Name) (eq $knownNetwork.Name "host"))) }}
  157. ## Can be connected with "{{ $containerNetwork.Name }}" network
  158. {{/* If only 1 port exposed, use that */}}
  159. {{ if eq $addrLen 1 }}
  160. {{ $address := index $container.Addresses 0 }}
  161. {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }}
  162. {{/* If more than one port exposed, use the one matching VIRTUAL_PORT env var, falling back to standard web port 80 */}}
  163. {{ else }}
  164. {{ $port := coalesce $container.Env.VIRTUAL_PORT "80" }}
  165. {{ $address := where $container.Addresses "Port" $port | first }}
  166. {{ template "upstream" (dict "Container" $container "Address" $address "Network" $containerNetwork) }}
  167. {{ end }}
  168. {{ else }}
  169. # Cannot connect to network of this container
  170. server 127.0.0.1 down;
  171. {{ end }}
  172. {{ end }}
  173. {{ end }}
  174. {{ end }}
  175. }
  176. {{ $default_host := or ($.Env.DEFAULT_HOST) "" }}
  177. {{ $default_server := index (dict $host "" $default_host "default_server") $host }}
  178. {{/* Get the VIRTUAL_PROTO defined by containers w/ the same vhost, falling back to "http" */}}
  179. {{ $proto := trim (or (first (groupByKeys $containers "Env.VIRTUAL_PROTO")) "http") }}
  180. {{/* Get the NETWORK_ACCESS defined by containers w/ the same vhost, falling back to "external" */}}
  181. {{ $network_tag := or (first (groupByKeys $containers "Env.NETWORK_ACCESS")) "external" }}
  182. {{/* Get the HTTPS_METHOD defined by containers w/ the same vhost, falling back to "redirect" */}}
  183. {{ $https_method := or (first (groupByKeys $containers "Env.HTTPS_METHOD")) "redirect" }}
  184. {{/* Get the SSL_POLICY defined by containers w/ the same vhost, falling back to empty string (use default) */}}
  185. {{ $ssl_policy := or (first (groupByKeys $containers "Env.SSL_POLICY")) "" }}
  186. {{/* Get the HSTS defined by containers w/ the same vhost, falling back to "max-age=31536000" */}}
  187. {{ $hsts := or (first (groupByKeys $containers "Env.HSTS")) "max-age=31536000" }}
  188. {{/* Get the VIRTUAL_ROOT By containers w/ use fastcgi root */}}
  189. {{ $vhost_root := or (first (groupByKeys $containers "Env.VIRTUAL_ROOT")) "/var/www/public" }}
  190. {{/* Get the first cert name defined by containers w/ the same vhost */}}
  191. {{ $certName := (first (groupByKeys $containers "Env.CERT_NAME")) }}
  192. {{/* Get the best matching cert by name for the vhost. */}}
  193. {{ $vhostCert := (closest (dir "/etc/nginx/certs") (printf "%s.crt" $host))}}
  194. {{/* vhostCert is actually a filename so remove any suffixes since they are added later */}}
  195. {{ $vhostCert := trimSuffix ".crt" $vhostCert }}
  196. {{ $vhostCert := trimSuffix ".key" $vhostCert }}
  197. {{/* Use the cert specified on the container or fallback to the best vhost match */}}
  198. {{ $cert := (coalesce $certName $vhostCert) }}
  199. {{ $is_https := (and (ne $https_method "nohttps") (ne $cert "") (exists (printf "/etc/nginx/certs/%s.crt" $cert)) (exists (printf "/etc/nginx/certs/%s.key" $cert))) }}
  200. {{ if $is_https }}
  201. {{ if eq $https_method "redirect" }}
  202. server {
  203. server_name {{ $host }};
  204. listen 80 {{ $default_server }};
  205. {{ if $enable_ipv6 }}
  206. listen [::]:80 {{ $default_server }};
  207. {{ end }}
  208. access_log /var/log/nginx/access.log vhost;
  209. # Do not HTTPS redirect Let'sEncrypt ACME challenge
  210. location /.well-known/acme-challenge/ {
  211. auth_basic off;
  212. allow all;
  213. root /usr/share/nginx/html;
  214. try_files $uri =404;
  215. break;
  216. }
  217. location / {
  218. return 301 https://$host$request_uri;
  219. }
  220. }
  221. {{ end }}
  222. server {
  223. server_name {{ $host }};
  224. listen 443 ssl http2 {{ $default_server }};
  225. {{ if $enable_ipv6 }}
  226. listen [::]:443 ssl http2 {{ $default_server }};
  227. {{ end }}
  228. access_log /var/log/nginx/access.log vhost;
  229. {{ if eq $network_tag "internal" }}
  230. # Only allow traffic from internal clients
  231. include /etc/nginx/network_internal.conf;
  232. {{ end }}
  233. {{ template "ssl_policy" (dict "ssl_policy" $ssl_policy) }}
  234. ssl_session_timeout 5m;
  235. ssl_session_cache shared:SSL:50m;
  236. ssl_session_tickets off;
  237. ssl_certificate /etc/nginx/certs/{{ (printf "%s.crt" $cert) }};
  238. ssl_certificate_key /etc/nginx/certs/{{ (printf "%s.key" $cert) }};
  239. {{ if (exists (printf "/etc/nginx/certs/%s.dhparam.pem" $cert)) }}
  240. ssl_dhparam {{ printf "/etc/nginx/certs/%s.dhparam.pem" $cert }};
  241. {{ end }}
  242. {{ if (exists (printf "/etc/nginx/certs/%s.chain.pem" $cert)) }}
  243. ssl_stapling on;
  244. ssl_stapling_verify on;
  245. ssl_trusted_certificate {{ printf "/etc/nginx/certs/%s.chain.pem" $cert }};
  246. {{ end }}
  247. {{ if (not (or (eq $https_method "noredirect") (eq $hsts "off"))) }}
  248. add_header Strict-Transport-Security "{{ trim $hsts }}" always;
  249. {{ end }}
  250. {{ if (exists (printf "/etc/nginx/vhost.d/%s" $host)) }}
  251. include {{ printf "/etc/nginx/vhost.d/%s" $host }};
  252. {{ else if (exists "/etc/nginx/vhost.d/default") }}
  253. include /etc/nginx/vhost.d/default;
  254. {{ end }}
  255. location / {
  256. {{ if eq $proto "uwsgi" }}
  257. include uwsgi_params;
  258. uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
  259. {{ else if eq $proto "fastcgi" }}
  260. root {{ trim $vhost_root }};
  261. include fastcgi_params;
  262. fastcgi_pass {{ trim $upstream_name }};
  263. {{ else if eq $proto "grpc" }}
  264. grpc_pass {{ trim $proto }}://{{ trim $upstream_name }};
  265. {{ else }}
  266. proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
  267. {{ end }}
  268. {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
  269. auth_basic "Restricted {{ $host }}";
  270. auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
  271. {{ end }}
  272. {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
  273. include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};
  274. {{ else if (exists "/etc/nginx/vhost.d/default_location") }}
  275. include /etc/nginx/vhost.d/default_location;
  276. {{ end }}
  277. }
  278. }
  279. {{ end }}
  280. {{ if or (not $is_https) (eq $https_method "noredirect") }}
  281. server {
  282. server_name {{ $host }};
  283. listen 80 {{ $default_server }};
  284. {{ if $enable_ipv6 }}
  285. listen [::]:80 {{ $default_server }};
  286. {{ end }}
  287. access_log /var/log/nginx/access.log vhost;
  288. {{ if eq $network_tag "internal" }}
  289. # Only allow traffic from internal clients
  290. include /etc/nginx/network_internal.conf;
  291. {{ end }}
  292. {{ if (exists (printf "/etc/nginx/vhost.d/%s" $host)) }}
  293. include {{ printf "/etc/nginx/vhost.d/%s" $host }};
  294. {{ else if (exists "/etc/nginx/vhost.d/default") }}
  295. include /etc/nginx/vhost.d/default;
  296. {{ end }}
  297. location / {
  298. {{ if eq $proto "uwsgi" }}
  299. include uwsgi_params;
  300. uwsgi_pass {{ trim $proto }}://{{ trim $upstream_name }};
  301. {{ else if eq $proto "fastcgi" }}
  302. root {{ trim $vhost_root }};
  303. include fastcgi_params;
  304. fastcgi_pass {{ trim $upstream_name }};
  305. {{ else if eq $proto "grpc" }}
  306. grpc_pass {{ trim $proto }}://{{ trim $upstream_name }};
  307. {{ else }}
  308. proxy_pass {{ trim $proto }}://{{ trim $upstream_name }};
  309. {{ end }}
  310. {{ if (exists (printf "/etc/nginx/htpasswd/%s" $host)) }}
  311. auth_basic "Restricted {{ $host }}";
  312. auth_basic_user_file {{ (printf "/etc/nginx/htpasswd/%s" $host) }};
  313. {{ end }}
  314. {{ if (exists (printf "/etc/nginx/vhost.d/%s_location" $host)) }}
  315. include {{ printf "/etc/nginx/vhost.d/%s_location" $host}};
  316. {{ else if (exists "/etc/nginx/vhost.d/default_location") }}
  317. include /etc/nginx/vhost.d/default_location;
  318. {{ end }}
  319. }
  320. }
  321. {{ if (and (not $is_https) (exists "/etc/nginx/certs/default.crt") (exists "/etc/nginx/certs/default.key")) }}
  322. server {
  323. server_name {{ $host }};
  324. listen 443 ssl http2 {{ $default_server }};
  325. {{ if $enable_ipv6 }}
  326. listen [::]:443 ssl http2 {{ $default_server }};
  327. {{ end }}
  328. access_log /var/log/nginx/access.log vhost;
  329. return 500;
  330. ssl_certificate /etc/nginx/certs/default.crt;
  331. ssl_certificate_key /etc/nginx/certs/default.key;
  332. }
  333. {{ end }}
  334. {{ end }}
  335. {{ end }}