nginx.tmpl 17 KB

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