Automated docker nginx proxy integrated with letsencrypt. Based on https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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